AdminController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <?php
  2. /**
  3. * MainController
  4. * Feel free to delete the methods and replace them with your own code.
  5. *
  6. * @author JieRen
  7. */
  8. class AdminController extends DooController {
  9. private $cashlimit = 100; // 充值金额奖励底限
  10. private $perlimit = 0.05; // 奖励百分比
  11. private $salelimit = 0.2; // 销售人员提成
  12. public $data;
  13. /**
  14. * 构造函数
  15. */
  16. function __construct() {
  17. session_start();
  18. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  19. }
  20. /**
  21. * 构造函数
  22. */
  23. function main() {
  24. if (empty($_SESSION['main'])) {
  25. return Doo::conf()->APP_URL . 'm';
  26. }
  27. Doo::loadModel('pay');
  28. $pay = new Pay();
  29. $unpaycount = $pay->count(array('where' => 'status="unpay" or status="waitting"', 'asArray' => TRUE));
  30. $this->data['unpaycount'] = $unpaycount;
  31. $thistime = time();
  32. $day = date('Y-m-d',$thistime);
  33. $today = strtotime($day);
  34. $yesterday = $today-86400;
  35. // Doo::loadModel('users');
  36. // $users = new Users();
  37. //已激活用户
  38. $todaysql='SELECT count(*) as count FROM `zh_users` left join `zh_users_switch` on `zh_users`.id=`zh_users_switch`.uid WHERE `regdate` between '. $today .' and '. $thistime.' and (`mobile`!="" or `actime`!=0)';
  39. $todayquery = Doo::db ()->query ( $todaysql );
  40. $todayuseraddnum = $todayquery->fetch();
  41. $yesterdaysql = 'SELECT count(*) as count FROM `zh_users` left join `zh_users_switch` on `zh_users`.id=`zh_users_switch`.uid WHERE `regdate` between '. $yesterday .' and '. $today.' and (`mobile`!="" or `actime`!=0)';
  42. $yesterdayquery = Doo::db ()->query ( $yesterdaysql );
  43. $yesterdayuseraddnum = $yesterdayquery->fetch();
  44. $this->data['tuaddnum'] = $todayuseraddnum['count'];
  45. $this->data['yuaddnum'] = $yesterdayuseraddnum['count'];
  46. //获取最近的12个月激活用户人数
  47. $monthstr = $muaddnumstr = array();
  48. $monthday = $thistime;
  49. for($i = 1; $i <= 12; $i++){
  50. $thismonth = date('m',$monthday);
  51. $thismonthday = intval($thismonth) >= 10 ? $thismonth.'月' : intval($thismonth).'月';
  52. array_unshift($monthstr,$thismonthday);
  53. $monthday = date('Y-m-d',$monthday);
  54. $endmonth = date('Y-m-01',strtotime("$monthday + 1 month"));
  55. $startmonth = date('Y-m-01',strtotime("$monthday - 1 month"));
  56. $monthsql = 'SELECT count(*) as count FROM `zh_users` left join `zh_users_switch` on `zh_users`.id=`zh_users_switch`.uid WHERE `regdate` between '. strtotime($startmonth) .' and '. strtotime($endmonth) .' and (`mobile`!="" or `actime`!=0)';
  57. $monthquery = Doo::db ()->query ( $monthsql );
  58. $monthuseraddnum = $monthquery->fetch();
  59. array_unshift($muaddnumstr,$monthuseraddnum['count']);
  60. $monthday = strtotime($startmonth);
  61. }
  62. $this->data['monthstr'] = $monthstr;
  63. $this->data['muaddnumstr'] = $muaddnumstr;
  64. //充值记录
  65. $alipaytodaycount = $pay->get_sum_succ_posts('alipay', $today, $thistime);
  66. $alipayyesterdaycount = $pay->get_sum_succ_posts('alipay', $yesterday, $today);
  67. $offlinetodaycount = $pay->get_sum_succ_posts('offline', $today, $thistime);
  68. $offlineyesterdaycount = $pay->get_sum_succ_posts('offline', $yesterday, $today);
  69. $this->data['atcount'] = $alipaytodaycount['sum'];
  70. $this->data['aycount'] = $alipayyesterdaycount['sum'];
  71. $this->data['otcount'] = $offlinetodaycount['sum'];
  72. $this->data['oycount'] = $offlineyesterdaycount['sum'];
  73. $this->data['alltcount'] = floatval($alipaytodaycount['sum'])+floatval($offlinetodaycount['sum']);
  74. $this->data['allycount'] = floatval($alipayyesterdaycount['sum'])+floatval($offlineyesterdaycount['sum']);
  75. //2015,2016年充值数据
  76. $yearstart2015 = 1420041600;
  77. $yearend2015 = 1451577599;
  78. $yearstart2016 = 1451577600;
  79. $yearend2016 = 1483199999;
  80. $alipay2015 = $pay->get_sum_succ_posts('alipay', $yearstart2015, $yearend2015);
  81. $alipay2016 = $pay->get_sum_succ_posts('alipay', $yearstart2016, $yearend2016);
  82. $offline2015 = $pay->get_sum_succ_posts('offline', $yearstart2015, $yearend2015);
  83. $offline2016 = $pay->get_sum_succ_posts('offline', $yearstart2016, $yearend2016);
  84. $recharge2015 = $pay->get_sum_succ_posts('recharge', $yearstart2015, $yearend2015);
  85. $recharge2016 = $pay->get_sum_succ_posts('recharge', $yearstart2016, $yearend2016);
  86. $all2015 = floatval($alipay2015['sum'])+floatval($offline2015['sum'])+floatval($recharge2015['sum']);
  87. $all2016 = floatval($alipay2016['sum'])+floatval($offline2016['sum'])+floatval($recharge2016['sum']);
  88. $this->data['alipay2015'] = $alipay2015['sum'];
  89. $this->data['alipay2016'] = $alipay2016['sum'];
  90. $this->data['offline2015'] = $offline2015['sum'];
  91. $this->data['offline2016'] = $offline2016['sum'];
  92. $this->data['recharge2015'] = $recharge2015['sum'];
  93. $this->data['recharge2016'] = $recharge2016['sum'];
  94. $this->data['all2015'] = $all2015;
  95. $this->data['all2016'] = $all2016;
  96. //2016每个月的充值数据
  97. $data2016 = array();
  98. for($i = 0; $i < 12; $i++){
  99. $j = $i+1;
  100. $data2016[$i]['month'] = $j.'月';
  101. $j = $j < 10 ? '0'.$j : $j;
  102. $nowmonth = '2016-'.$j.'-01';
  103. $starttime = strtotime($nowmonth);
  104. $endtime = strtotime("+1 months", strtotime($nowmonth))-1;
  105. $alipay = $pay->get_sum_succ_posts('alipay', $starttime, $endtime);
  106. $offline = $pay->get_sum_succ_posts('offline', $starttime, $endtime);
  107. $recharge = $pay->get_sum_succ_posts('recharge', $starttime, $endtime);
  108. $allpost = floatval($alipay['sum'])+floatval($offline['sum'])+floatval($recharge['sum']);
  109. $data2016[$i]['alipay'] = empty($alipay['sum']) ? 0 : $alipay['sum'] ;
  110. $data2016[$i]['offline'] = empty($offline['sum']) ? 0 : $offline['sum'];
  111. $data2016[$i]['recharge'] = empty($recharge['sum']) ? 0 : $recharge['sum'];
  112. $data2016[$i]['allpost'] = $allpost;
  113. }
  114. $this->data['data2016'] = $data2016;
  115. //总充值总计
  116. $firsttime = mktime(0,0,0,11,1,2012);
  117. $all = $pay->getOne(array('select' => 'sum(money) as sum', 'where' => 'status="succ" and addtime between '. $firsttime .' and '. $thistime, 'asArray' => TRUE));
  118. $this->data['all'] = round($all['sum'],2);
  119. $this->data['selectindex'] = true;
  120. $this->render('admin/admin-index', $this->data);
  121. }
  122. public function mainCharts(){
  123. //获取最近的30天充值记录
  124. Doo::loadModel('pay');
  125. $thistime = time();
  126. $day = date('Y-m-d',$thistime);
  127. $endtime = strtotime($day)+86400;
  128. $starttime = strtotime("$day - 1 month")+86400;
  129. $hadnum = ($endtime-$starttime)/86400;
  130. $lastday = $endtime;
  131. $daystr = $alipaystr = $offlinestr = $allstr = array();
  132. for($i = 1; $i <= $hadnum; $i++){
  133. $pay = new Pay();
  134. $addoneday = date('Y-m-d',$lastday);
  135. $lastday = strtotime("$addoneday - 1 day");
  136. $monthnum = date('m',$lastday);
  137. $daynum = date('d',$lastday);
  138. $thisday = intval($daynum);
  139. $starttoday = date('Y',$lastday).'-'.$monthnum.'-'.$daynum;
  140. $endtoday = date('Y-m-d',strtotime("$starttoday + 1 day"));
  141. array_unshift($daystr,$thisday);
  142. $alipaycount = $pay->get_sum_succ_posts('alipay', strtotime($starttoday), strtotime($endtoday));
  143. $alipaycount = empty($alipaycount['sum']) ? 0 : floatval($alipaycount['sum']);
  144. array_unshift($alipaystr,$alipaycount);
  145. $offlinecount = $pay->get_sum_succ_posts('offline', strtotime($starttoday), strtotime($endtoday));
  146. $offlinecount = empty($offlinecount['sum']) ? 0 : floatval($offlinecount['sum']);
  147. array_unshift($offlinestr,$offlinecount);
  148. array_unshift($allstr,floatval($alipaycount)+floatval($offlinecount));
  149. }
  150. echo json_encode(array("daystr" => $daystr, "alipaystr" => $alipaystr, "offlinestr" => $offlinestr, 'allstr' => $allstr));
  151. exit;
  152. }
  153. /**
  154. * 默认路由、登陆
  155. */
  156. public function login() {
  157. if (!empty($_SESSION['main'])) {
  158. return Doo::conf()->APP_URL . 'm/main';
  159. }
  160. if (!empty($_POST['username']) && !empty($_POST['password'])) {
  161. $username = addslashes($_POST['username']);
  162. $password = addslashes($_POST['password']);
  163. $muser = Doo::loadModel('m/musers', TRUE);
  164. $userArray = $muser->getOne(array(
  165. 'select' => 'username,password,salt',
  166. 'where' => 'username=?',
  167. 'param' => array($username),
  168. 'limit' => 1,
  169. 'asArray' => TRUE,
  170. ));
  171. $pwd = md5(md5($password) . $userArray['salt']);
  172. $newpwd = $userArray['password'];
  173. if ($pwd == $newpwd) {
  174. $_SESSION['main'] = 'Main';
  175. $_SESSION['userArray'] = $userArray;
  176. return Doo::conf()->APP_URL . 'm/main';
  177. }
  178. } else {
  179. $this->render('admin/login', $this->data, TRUE);
  180. }
  181. }
  182. /**
  183. * 录入
  184. */
  185. public function addcity() {
  186. if (empty($_SESSION['main'])) {
  187. return Doo::conf()->APP_URL . 'm';
  188. }
  189. Doo::loadModel('category');
  190. $cat = new Category();
  191. if (!empty($_POST['citysubmit'])) {
  192. $cat->add_cat(htmlspecialchars($_POST['categoryname']), intval($_POST['acsel']));
  193. echo '添加完毕';
  194. }
  195. $this->data['arrcat'] = $cat->get_all();
  196. $this->render('admin/addcity', $this->data);
  197. }
  198. /**
  199. *
  200. * @param type $param
  201. */
  202. public function user($param) {
  203. $this->render('admin/addcity', $this->data);
  204. }
  205. /**
  206. *
  207. * @param type $param
  208. */
  209. public function logout() {
  210. $_SESSION['main'] = NULL;
  211. session_destroy();
  212. session_unset();
  213. return Doo::conf()->APP_URL . 'm';
  214. }
  215. /**
  216. *
  217. * @param type $param
  218. */
  219. public function userAdd() {
  220. if (empty($_SESSION['main'])) {
  221. return Doo::conf()->APP_URL . 'm';
  222. }
  223. Doo::loadModel('users');
  224. $user = new Users();
  225. // 添加用户方法
  226. // if (!empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['useremail'])) {
  227. // $username = addslashes(htmlspecialchars($_POST['username']));
  228. // $useremail = addslashes(htmlspecialchars($_POST['useremail']));
  229. // $password = addslashes(htmlspecialchars($_POST['password']));
  230. // $salt = $this->create_randomstr();
  231. // $muserArray = array('username' => $username, 'userpasswd' => $this->create_password($password, $salt), 'useremail' => $useremail, 'salt' => $salt, 'clientip' => $this->clientIP());
  232. // if ($user->userAdd($muserArray))
  233. // return Doo::conf()->APP_URL . 'm/user';
  234. // }
  235. // END
  236. if (!empty($_POST['searchuser']) && !empty($_POST['ttt'])) {
  237. // if (!empty($_POST['username'])) {
  238. // $totalArchive = $user->count(array('select' => 'username,useremail,lastloginip,lastlogintime', 'where' => 'username=?', 'param' => array($_POST['username']), 'limit' => '1', 'asArray' => TRUE));
  239. // } elseif (!empty($_POST['useremail'])) {
  240. // $totalArchive = $user->count(array('where' => 'useremail=?', 'param' => array($_POST['useremail']), 'asArray' => TRUE));
  241. // } else
  242. if ($this->isMail($_POST['ttt'])) {
  243. $totalArchive = $user->count(array('where' => 'useremail=?', 'param' => array(trim($_POST['ttt'])), 'asArray' => TRUE));
  244. // if(empty($totalArchive))
  245. // $totalArchive = $user->count(array('where' => 'username=?', 'param' => array(trim($_POST['ttt'])), 'asArray' => TRUE));
  246. }
  247. else if($this->isMobile($_POST['ttt'])) {
  248. $totalArchive = $user->count(array('where' => 'mobile=?', 'param' => array(trim($_POST['ttt'])), 'asArray' => TRUE));
  249. }else {
  250. $totalArchive = $user->count(array('where' => 'username=?', 'param' => array(trim($_POST['ttt'])), 'asArray' => TRUE));
  251. }
  252. } else {
  253. $totalArchive = $user->count();
  254. }
  255. Doo::loadHelper('DooPager');
  256. $pager = new DooPager(Doo::conf()->APP_URL . "m/user/page", $totalArchive, 30, 10);
  257. if (!empty($this->params['pindex']))
  258. $pager->paginate(intval($this->params['pindex']));
  259. else
  260. $pager->paginate(1);
  261. if (!empty($_POST['searchuser']) && !empty($_POST['ttt'])) {
  262. $this->data['search'] = true;
  263. // if (isset($_POST['username'])) {
  264. // $userArray = $user->getOne(array('where' => 'username=?', 'param' => array($_POST['username']), 'asArray' => TRUE));
  265. // } elseif (isset($_POST['useremail'])) {
  266. // $userArray = $user->getOne(array('where' => 'useremail=?', 'param' => array($_POST['useremail']), 'asArray' => TRUE));
  267. // } else
  268. if ($this->isMail($_POST['ttt'])) {
  269. $userArray[0] = $user->getOne(array('where' => 'useremail=?', 'param' => array(trim($_POST['ttt'])), 'asArray' => TRUE));
  270. // if(empty($userArray[0]))
  271. // $userArray[0] = $user->getOne(array('where' => 'username=?', 'param' => array(trim($_POST['ttt'])), 'asArray' => TRUE));
  272. } elseif($this->isMobile($_POST['ttt'])) {
  273. $userArray[0] = $user->getOne(array('where' => 'mobile=?', 'param' => array(trim($_POST['ttt'])), 'asArray' => TRUE));
  274. }else {
  275. $userArray[0] = $user->getOne(array('where' => 'username=?', 'param' => array(trim($_POST['ttt'])), 'asArray' => TRUE));
  276. }
  277. } else {
  278. $userArray = $user->getAll($pager->limit);
  279. }
  280. foreach($userArray as $k => $v){
  281. $userArray[$k]['status'] = self::isUserActive($v['id']);
  282. }
  283. $this->data['pager'] = $pager->output;
  284. $this->data['userArray'] = $userArray;
  285. $this->data['selectuser'] = true;
  286. $this->render('admin/user', $this->data, TRUE);
  287. }
  288. /**
  289. *
  290. * @param $password 密码
  291. * @param $random 随机数
  292. */
  293. function create_password($password = '', $random = '') {
  294. if (empty($random)) {
  295. $array['random'] = $this->create_randomstr();
  296. $array['password'] = md5(md5($password) . $array['random']);
  297. return $array;
  298. }
  299. return md5(md5($password) . $random);
  300. }
  301. /**
  302. * 生成随机字符串
  303. * @param string $lenth 长度
  304. * @return string 字符串
  305. */
  306. function create_randomstr($lenth = 6) {
  307. return $this->random($lenth, '123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ');
  308. }
  309. /**
  310. * 随机字符串函数
  311. * @param $password 密码
  312. * @param $random 随机数
  313. */
  314. function random($length, $chars = '0123456789') {
  315. $hash = '';
  316. $max = strlen($chars) - 1;
  317. for ($i = 0; $i < $length; $i++) {
  318. $hash .= $chars[mt_rand(0, $max)];
  319. }
  320. return $hash;
  321. }
  322. /**
  323. *
  324. * @param type $param
  325. */
  326. public function adminAdd() {
  327. if (empty($_SESSION['main'])) {
  328. return Doo::conf()->APP_URL . 'm';
  329. }
  330. Doo::loadModel('m/musers');
  331. $musers = new Musers();
  332. // 添加用户方法
  333. if (!empty($_POST['username']) && !empty($_POST['password'])) {
  334. $username = addslashes(htmlspecialchars($_POST['username']));
  335. $password = addslashes(htmlspecialchars($_POST['password']));
  336. $salt = $this->create_randomstr();
  337. $muserArray = array('username' => $username, 'password' => $this->create_password($password, $salt), 'groups' => 'admin', 'salt' => $salt);
  338. if ($musers->muserAdd($muserArray))
  339. return Doo::conf()->APP_URL . 'm/admin';
  340. }
  341. // END
  342. $totalArchive = $musers->getCountz();
  343. Doo::loadHelper('DooPager');
  344. $pager = new DooPager(Doo::conf()->APP_URL . "m/admin/page", $totalArchive, 2, 5);
  345. if (!empty($this->params['pindex']))
  346. $pager->paginate(intval($this->params['pindex']));
  347. else
  348. $pager->paginate(1);
  349. $userArray = $musers->getAll($pager->limit);
  350. $this->data['pager'] = $pager->output;
  351. $this->data['userArray'] = $userArray;
  352. $this->data['selectuser'] = true;
  353. $this->render('admin/admin', $this->data, TRUE);
  354. }
  355. /**
  356. *
  357. * @param type $param
  358. */
  359. public function mainIndex() {
  360. $this->render('admin/gloablStyle', $this->data, TRUE);
  361. }
  362. public function payStatus(){
  363. $id=isset($_POST['id'])?$_POST['id']:'';
  364. $username=isset($_POST['username'])?$_POST['username']:"";
  365. if(empty($id)||empty($username))
  366. return false;
  367. Doo::loadModel('pay');
  368. $pay = new Pay();
  369. $pinfo=$pay->getRowByUid($id);
  370. if($pinfo['status']=='waitting'||$pinfo['status']=='unpay'){
  371. $p = new Pay();
  372. $p->id=$id;
  373. $p->paytime=time();
  374. $p->checker=$username;
  375. $p->adminnote=2;
  376. $p->status="succ";
  377. if($pinfo['money']>0){
  378. if(!empty($pinfo['telephone'])&&($pinfo['money']>=$this->cashlimit)){
  379. $salerGet = floor($pinfo['money']*$this->salelimit); // 计算销售人员获得的提成
  380. $pinfo['money'] += floor($pinfo['money']*$this->perlimit);
  381. Doo::loadModel('m/sale');
  382. $saleObj = new Sale();
  383. $saleObj->total = new DooDbExpression('total+' . $salerGet);
  384. $saleObj->update(array('where'=>'promocode=?','param'=>array($pinfo['telephone'])));
  385. }
  386. Doo::loadModel('users');
  387. $user = new Users();
  388. $k=$user->updateBank($pinfo['userid'], $pinfo['money']);
  389. if($k){
  390. Doo::loadModel('income_pay');
  391. $incomepay = new IncomePay();
  392. $incomepay->uid = $pinfo['userid'];
  393. $incomepay->money = $pinfo['money'];
  394. $incomepay->type = 1;
  395. $incomepay->comefrom = $pinfo['payment'];
  396. $incomepay->addtime = time();
  397. $incomepay->insert();
  398. $p->update();
  399. // echo '{"success": true}';die;
  400. }
  401. }
  402. }
  403. return '/m/pay/add';
  404. }
  405. /**
  406. *
  407. */
  408. public function pay() {
  409. if (empty($_SESSION['main'])) {
  410. return Doo::conf()->APP_URL . 'm';
  411. }
  412. if (isset($_GET['op']) && !empty($_POST['ids'])) {
  413. $ops = $_GET['op'];
  414. // $ids = implode(',', $_POST['ids']);
  415. $ids = $_POST['ids'];
  416. Doo::loadModel('pay');
  417. $p = new Pay();
  418. if (!empty($ids)) {
  419. if ($ops == 'del') {
  420. foreach ($ids as $key => $val) {
  421. $p->id = $val;
  422. $p->delete();
  423. }
  424. }
  425. if ($ops == 'act') {
  426. foreach ($ids as $key => $val) {
  427. $p->status = 'succ';
  428. $p->update(array('where' => 'id=' . $val));
  429. }
  430. }
  431. }
  432. }
  433. $status=isset($_GET['status'])?$_GET['status']:'1';
  434. if($status==1&&isset($this->params['status']))
  435. $status=urldecode($this->params['status']);
  436. $search = isset($_GET['search'])?$_GET['search']:'1';
  437. if($search==1&&isset($this->params['search']))
  438. $search=$this->params['search'];
  439. $s='all';
  440. $ss = $sql1 = $sql2 = '';
  441. if($status=="succ"){
  442. $s='succ';
  443. $sql1.="status='succ'";
  444. }elseif($status=="waitting:unpay"){
  445. $s='waitting:unpay';
  446. $sql1.="(status='waitting' or status='unpay')";
  447. }
  448. if($search!=1){
  449. $ss = $search.'/';
  450. Doo::loadModel('users');
  451. $users = new Users();
  452. $id = $users->getidBysearch($search);
  453. if(isset($id['id'])){
  454. $sql2 .= 'userid='.$id['id'];
  455. }else{
  456. $sql2 = 'username="'.$search.'"';
  457. }
  458. }
  459. if(empty($sql2) && empty($sql1)){
  460. $sql = ' 1';
  461. }elseif(!empty($sql2) && empty($sql1)){
  462. $sql = $sql2;
  463. }elseif(empty($sql2) && !empty($sql1)){
  464. $sql = $sql1;
  465. }else{
  466. $sql = $sql2 . ' and '. $sql1;
  467. }
  468. Doo::loadHelper('DooPager');
  469. Doo::loadModel('pay');
  470. $pay = new Pay();
  471. $totalArchive = $pay->count(array('where' => $sql));
  472. $pager = new DooPager(Doo::conf()->APP_URL . "m/pay/add/page/".$ss.$s, $totalArchive, 30, 10);
  473. if (isset($this->params['pindex']))
  474. $pager->paginate(intval($this->params['pindex']));
  475. else
  476. $pager->paginate(1);
  477. $this->data['status']=$s;
  478. $this->data['search']= $search != 1 ? $search : '';
  479. if ($pager->limit != ' -30,30')
  480. $this->data['userArray'] = $pay->get_all_posts_status($pager->limit,$sql);
  481. // var_dump($this->data['userArray']);
  482. if(isset($this->data['userArray']) && !empty($this->data['userArray'])) {
  483. foreach ($this->data['userArray'] as $key => $value) {
  484. if (!empty($value['telephone']) && ($value['money'] >= $this->cashlimit)) {
  485. Doo::loadModel('m/sale');
  486. $saleObj = new Sale();
  487. $saleArray = $saleObj->getOne(array('where' => 'promocode=?', 'param' => array($value['telephone']), 'asArray' => TRUE));
  488. $this->data['userArray'][$key]['info'] = '(多送5%[' . $value['money'] * $this->perlimit . '元],' . $saleArray['salename'] . ')';
  489. }
  490. Doo::loadModel('users');
  491. $users = new Users();
  492. $user = $users->getRowByid($value['userid']);
  493. $this->data['userArray'][$key]['mobile'] = $user['mobile'];
  494. $this->data['userArray'][$key]['email'] = $user['useremail'];
  495. $this->data['userArray'][$key]['status2'] = self::isUserActive($value['userid']);
  496. }
  497. }
  498. $this->data['pager'] = $pager->output;
  499. $this->data['selectorder'] = true;
  500. $this->render('admin/pay', $this->data, TRUE);
  501. }
  502. /**
  503. *
  504. */
  505. public function payModify() {
  506. if (empty($_SESSION['main'])) {
  507. return Doo::conf()->APP_URL . 'm';
  508. }
  509. $id = intval($this->params['pid']);
  510. if (empty($id))
  511. return false;
  512. $money = isset($_POST['money']) ? intval($_POST['money']) : NULL;
  513. if (!empty($money)) {
  514. Doo::loadModel('pay');
  515. $pay = new Pay();
  516. // $pay->money = new DooDbExpression('money+' . $money);
  517. $pay->money = $money;
  518. $pay->update(array('where' => 'id=' . $id));
  519. return Doo::conf()->APP_URL . 'm/pay/add';
  520. }
  521. // Doo::loadModel('pay');
  522. // $pay = new Pay();
  523. // $this->data['userArray'] = $pay->getRowByUid($id);
  524. return '/m/pay/add';
  525. // $this->render('admin/pay_modify', $this->data, TRUE);
  526. }
  527. public function voucherList(){
  528. if (empty($_SESSION['main'])) {
  529. return Doo::conf()->APP_URL . 'm';
  530. }
  531. Doo::loadModel('voucher');
  532. $voucher = new Voucher();
  533. Doo::loadHelper('DooPager');
  534. $countsql = $sql = '';
  535. $this->data['starttime'] = strtotime(date("Y-m-d",strtotime("+1 day")));
  536. if(isset($this->params['status']) && is_numeric($this->params['status'])){
  537. $sql = 'status='.$this->params['status'];
  538. $countsql = 'status/'.$this->params['status'].'/';
  539. $this->data['status'] = $this->params['status'];
  540. }
  541. if(!empty($sql)){
  542. $totalArchive = $voucher->count(array('where' => $sql));
  543. }else{
  544. $totalArchive = $voucher->count();
  545. }
  546. $pager = new DooPager(Doo::conf()->APP_URL . "m/voucher/".$countsql, $totalArchive, 30, 10);
  547. if (isset($this->params['pindex']))
  548. $pager->paginate(intval($this->params['pindex']));
  549. else
  550. $pager->paginate(1);
  551. if ($pager->limit != ' -30,30')
  552. $voucherlist = $voucher->getAll($sql,$pager->limit);
  553. if(isset($voucherlist) && !empty($voucherlist)){
  554. $thistime = time();
  555. $this->data['thistime'] = $thistime;
  556. foreach($voucherlist as $k => $v){
  557. Doo::loadModel('users_voucher');
  558. $uservoucher = new UsersVoucher();
  559. if($thistime>=$v['vstarttime'] && $thistime<$v['vendtime']){
  560. $voucherlist[$k]['status'] = 1;
  561. }
  562. $voucherlist[$k]['hadnum'] = $uservoucher->count(array('where' => 'vid='.$v['id']));
  563. if(($v['vcount'] != 0 && $voucherlist[$k]['hadnum'] >= $v['vcount']) || $thistime>=$v['vendtime']){
  564. $voucherlist[$k]['status'] = 2;
  565. }
  566. if($voucherlist[$k]['status'] != 0){
  567. $voucher2 = new Voucher();
  568. $voucher2->id = $v['id'];
  569. $voucher2->status = $voucherlist[$k]['status'];
  570. $voucher2->update();
  571. }
  572. }
  573. $this->data['voucherlist'] = $voucherlist;
  574. }
  575. $this->data['pager'] = $pager->output;
  576. $this->data['selectvoucher'] = true;
  577. $this->render('admin/voucher', $this->data, TRUE);
  578. }
  579. public function setVoucher(){
  580. if(!isset($_POST['vname']) || empty($_POST['vname'])){
  581. exit('活动名不能为空');
  582. }
  583. if(!isset($_POST['vcost']) || empty($_POST['vcost'])){
  584. exit('金额不能为空');
  585. }
  586. if(!isset($_POST['starttime']) || empty($_POST['starttime'])){
  587. exit('请选择开始日期');
  588. }
  589. if(!isset($_POST['endtime']) || empty($_POST['endtime'])){
  590. exit('请选择结束日期');
  591. }
  592. if(isset($_POST['vcount']) && is_int($_POST['vcount'])){
  593. exit('代金券数量只能为整数');
  594. }
  595. if(strtotime($_POST['starttime'].' 00:00:00') < time()){
  596. exit('开始时间不能小于或等于活动添加当天');
  597. }
  598. if(strtotime($_POST['endtime'].' 23:59:59') < strtotime($_POST['starttime'].' 00:00:00')){
  599. exit('结束时间不能小于开始时间');
  600. }
  601. Doo::loadModel('voucher');
  602. $voucher = new Voucher();
  603. $voucher->vname = $_POST['vname'];
  604. $voucher->vcode = $this->MadeCode();
  605. $voucher->vcost = $_POST['vcost'];
  606. $voucher->vcount = empty($_POST['vcount']) ? 0 : $_POST['vcount'];
  607. $voucher->vstarttime = strtotime($_POST['starttime'].' 00:00:00');
  608. $voucher->vendtime = strtotime($_POST['endtime'].' 23:59:59');
  609. $voucher->vaddtime = time();
  610. $voucher->status = 0;
  611. $voucher->insert();
  612. return '/m/voucher';
  613. }
  614. public function delVoucher(){
  615. if(isset($this->params['vid']) && is_numeric($this->params['vid'])){
  616. Doo::loadModel('voucher');
  617. $voucher = new Voucher();
  618. $voucher->id = $this->params['vid'];
  619. $voucher->delete();
  620. }
  621. return '/m/voucher';
  622. }
  623. function isMail($mail) {
  624. if (preg_match("/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9\-\.])+/", $mail))
  625. return true;
  626. else
  627. return false;
  628. }
  629. function isMobile($mobile) {
  630. if(preg_match("/^1[34578]{1}\d{9}$/",$mobile)){
  631. return TRUE;
  632. } else {
  633. return FALSE;
  634. }
  635. }
  636. private static function isUserActive($uid) {
  637. Doo::loadModel('userswitch');
  638. $userswitch = new UserSwitch();
  639. return $userswitch->checkUserStatus($uid);
  640. }
  641. //随机生成6位的项目领取码
  642. private function MadeCode(){
  643. $string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  644. $code = '';
  645. for($i = 0; $i < 6; $i++){
  646. $index = rand(0,61);
  647. $code .= substr($string,$index,1);
  648. }
  649. return $code;
  650. }
  651. // public function payUpdate(){
  652. // Doo::loadModel('pay');
  653. // $pay = new Pay();
  654. // $paylist = $pay->find(array('where' => 'status="succ"', 'asArray' => TRUE));
  655. // Doo::loadModel('income_pay');
  656. // foreach($paylist as $k => $v){
  657. // $incomepay = new IncomePay();
  658. // $incomepay->uid = $v['userid'];
  659. // $incomepay->money = $v['money'];
  660. // $incomepay->type = 1;
  661. // if($v['pay_type'] == 'voucher'){
  662. // $incomepay->comefrom = '代金券';
  663. // $incomepay->description = $v['payment'];
  664. // }else{
  665. // $incomepay->comefrom = $v['payment'];
  666. // if(!empty($v['checker'])){
  667. // $incomepay->description = $v['checker'];
  668. // }
  669. // }
  670. // $incomepay->addtime = $v['addtime'];
  671. // $incomepay->insert();
  672. // }
  673. // }
  674. }
  675. ?>