BooksController.php 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use app\weixin\model\AccountLog;
  13. use app\weixin\model\Books;
  14. use app\weixin\model\UserRechargeLog;
  15. use app\weixin\model\Wechat;
  16. use cmf\controller\AdminBaseController;
  17. use think\Db;
  18. use think\db\Query;
  19. use app\admin\model\BooksModel;
  20. use app\weixin\service\Activity;
  21. use app\weixin\service\PRedis;
  22. /**
  23. * Class UserController
  24. * @package app\admin\controller
  25. * @adminMenuRoot(
  26. * 'name' => '管理组',
  27. * 'action' => 'default',
  28. * 'parent' => 'user/AdminIndex/default',
  29. * 'display'=> true,
  30. * 'order' => 10000,
  31. * 'icon' => '',
  32. * 'remark' => '管理组'
  33. * )
  34. */
  35. class BooksController extends AdminBaseController
  36. {
  37. /**
  38. * 活动报名名额显示列表
  39. */
  40. public function index()
  41. {
  42. /**搜索条件**/
  43. $keyword = $this->request->param('keyword');
  44. //$userEmail = trim($this->request->param('user_email'));
  45. // echo $keyword;die;
  46. $books = Db::name('books')
  47. ->alias('b')
  48. ->join('user u', 'b.uid = u.id', 'left')
  49. ->join('activity a', 'b.aid = a.id', 'left')
  50. ->where('b.aid', input('id'))
  51. ->where('b.status', 'neq', 1)
  52. ->where('b.status', 'neq', 4)
  53. ->where(function (Query $query) use ($keyword) {
  54. if ($keyword) {
  55. $query->where('u.user_nickname|b.book_num', 'like', "%$keyword%");
  56. }
  57. })
  58. ->field("a.title,u.user_nickname,u.id as uids,u.is_vip,b.*")
  59. ->order("b.id DESC")
  60. ->paginate(20, false, ['query' => request()->param()]);
  61. // echo Db::name('books')->getLastSql();die;
  62. //$books->appends(['nick_name' => $nick_name]);
  63. // 获取分页显示
  64. $page = $books->render();
  65. $this->assign("page", $page);
  66. $this->assign("books", !empty($books)? $books : null);
  67. return $this->fetch();
  68. }
  69. /**
  70. * 所有互选情况
  71. */
  72. public function allhuxuan()
  73. {
  74. /**搜索条件**/
  75. $nick_name = $this->request->param('nick_name');
  76. $books = Db::name('user_heart_match')
  77. ->alias('hm')
  78. ->join('user u', 'hm.uid= u.id', 'left')
  79. ->join('books b', 'b.uid=hm.uid and b.aid=hm.aid', 'left')
  80. ->where(function ($query) use ($nick_name) {
  81. if ($nick_name) {
  82. return $query->where('u.user_nickname', 'like', "%{$nick_name}%");
  83. }
  84. })
  85. // ->where(function (Query $query) use ($nick_name) {
  86. // })
  87. ->where(['b.status' => 3])
  88. ->where('hm.aid', input('id'))
  89. ->field("hm.id,u.user_nickname,hm.uid,hm.match_uid,hm.heart_uids,hm.`status`,hm.match_at,b.book_num")
  90. ->order("hm.status ASC")
  91. ->paginate(20, false, ['query' => request()->param()])
  92. ->each(function ($item, $key) {
  93. //显示编号
  94. // $booksary=Db::name('books')->field('book_num')
  95. // ->where('uid','in',$item['match_uid'])
  96. // ->where('aid',input('id'))
  97. // ->where('status',3)
  98. // ->find();
  99. $booksary = Db::name('books')->where(['aid' => input('id'), 'status' => 3])
  100. ->where('uid', 'in', $item['match_uid'])
  101. ->orderField('uid', explode(',', $item['match_uid']))
  102. ->column('book_num');
  103. //echo Db::name('books')->getLastSql();die;
  104. $item['match_name'] = implode(',', $booksary);
  105. $bookNums = Db::name('books')->where(['aid' => input('id'), 'status' => 3])
  106. ->where('uid', 'in', $item['heart_uids'])
  107. ->orderField('uid', explode(',', $item['heart_uids']))
  108. ->column('book_num');
  109. // echo Db::name('books')->getLastSql();die;
  110. // var_dump($bookNums);die;
  111. $item['heart_name'] = implode(',', $bookNums);
  112. //选我的人
  113. /*$htme='';
  114. $htmeary=Db::name('user_heart_match')
  115. ->alias('hm')
  116. ->field('b.book_num')
  117. ->join('books b','hm.uid=b.uid')
  118. ->where('find_in_set(:uid,hm.heart_uids)',['uid'=>$item['uid']])
  119. ->where('hm.aid',input('id'))
  120. ->where('b.status',3)
  121. ->select();
  122. // echo Db::name('user_heart_match')->getLastSql();die;
  123. foreach ($htmeary as $key => $value) {
  124. if($key<count($htmeary)-1){
  125. $htme.=$value['book_num'].',';
  126. }
  127. else{
  128. $htme.=$value['book_num'];
  129. }
  130. }*/
  131. $chooseArr = Db::name('user_heart_match')
  132. ->alias('hm')
  133. ->field('b.book_num')
  134. ->join('books b', 'hm.uid=b.uid and b.aid=hm.aid')
  135. ->where('find_in_set(:uid,hm.heart_uids)', ['uid' => $item['uid']])
  136. ->where('hm.aid', input('id'))
  137. ->where('b.status', 3)
  138. ->orderRaw("find_in_set('" . $item['uid'] . "',hm.heart_uids)")
  139. ->column('b.book_num'); // echo Db::name('user_heart_match')->getLastSql();die;
  140. $item['chooseme'] = $chooseArr ? implode(',', $chooseArr) : '';
  141. return $item;
  142. });
  143. // echo Db::name('user_heart_match')->getLastSql();
  144. // 获取分页显示
  145. $page = $books->render();
  146. //echo Db::name('user_heart_match')->getLastSql();die;
  147. $this->assign("page", $page);
  148. $this->assign("books", $books);
  149. return $this->fetch();
  150. }
  151. //增加活动
  152. public function add()
  153. {
  154. return $this->fetch('add');
  155. }
  156. /**
  157. * 活动添加提交
  158. */
  159. public function addPost()
  160. {
  161. if ($this->request->isPost()) {
  162. $data = $this->request->param();
  163. $activityModel = new ActivityModel();
  164. $result = $this->validate($data, 'Activity');
  165. if ($result !== true) {
  166. $this->error($result);
  167. }
  168. $data['starttime'] = strtotime($data['starttime']);
  169. $data['endtime'] = strtotime($data['endtime']);
  170. $data['addtime'] = time();
  171. $activityModel->allowField(true)->save($data);
  172. $this->success("添加成功!", url("Link/index"));
  173. }
  174. }
  175. /**
  176. * 活动编辑
  177. */
  178. public function edit()
  179. {
  180. $id = $this->request->param('id', 0, 'intval');
  181. $ActivityModel = new ActivityModel();
  182. $activity = $ActivityModel->get($id);
  183. $this->assign('activity', $activity);
  184. return $this->fetch();
  185. }
  186. /**
  187. * 活动编辑提交
  188. */
  189. public function editPost()
  190. {
  191. $data = $this->request->param();
  192. //处理开始时间和结束时间,转换为时间戳。
  193. if (strtotime($data['starttime']) > strtotime($data['endtime'])) {
  194. $this->error('活动结束时间不能大于开始时间!');
  195. }
  196. $data['starttime'] = strtotime($data['starttime']); //开始时间
  197. $data['endtime'] = strtotime($data['endtime']); //结束时间
  198. $activityModel = new ActivityModel();
  199. $result = $this->validate($data, 'Activity');
  200. if ($result !== true) {
  201. $this->error($result);
  202. }
  203. $activityModel->allowField(true)->isUpdate(true)->save($data);
  204. $this->success("保存成功!", url("Activity/index"));
  205. }
  206. /**
  207. * 删除活动编辑
  208. *
  209. */
  210. public function delete()
  211. {
  212. $id = $this->request->param('id', 0, 'intval');
  213. ActivityModel::destroy($id);
  214. $this->success("删除成功!", url("Activity/index"));
  215. }
  216. /**
  217. * 报名列表退款
  218. *
  219. */
  220. public function refund()
  221. {
  222. $id = $this->request->param('id', 0, 'intval');
  223. $aid = $this->request->param('aid', 0, 'intval');
  224. $booksModel = new BooksModel();
  225. $data['id'] = $id;
  226. $data['status'] = 5; //表示已退款
  227. //代表线上的活动id,为单身推荐的活动下的用户
  228. if ($aid == 15) {
  229. //变更is_tuijian=0
  230. $result = Db::name('user')->where('id', input('uid'))->update(['is_tuijian' => 0]);
  231. if ($result) {
  232. $booksModel->isUpdate(true)->save($data);
  233. $this->success("退款成功!", url("Books/index", ['id' => input('aid')]));
  234. } else {
  235. $this->error("退款失败!", url("Books/index", ['id' => input('aid')]));
  236. }
  237. } else {
  238. $booksModel->isUpdate(true)->save($data);
  239. $this->success("退款成功!", url("Books/index", ['id' => input('aid')]));
  240. }
  241. }
  242. /**
  243. * 活动退款打款处理
  244. * @throws \think\Exception
  245. * @throws \think\db\exception\DataNotFoundException
  246. * @throws \think\db\exception\ModelNotFoundException
  247. * @throws \think\exception\DbException
  248. * @throws \think\exception\PDOException
  249. */
  250. public function refundPay()
  251. {
  252. $id = $this->request->param('id', 0, 'intval');
  253. $money = $this->request->param('money', 0, 'float');
  254. $type = $this->request->param('type', 0, 'float');
  255. $remark = $this->request->param('remark', '');
  256. if ($money <= 0) {
  257. $this->error("请填写退款金额");
  258. }
  259. $info = Books::alias('b')
  260. ->leftJoin('activity a', 'a.id=b.aid')
  261. ->leftJoin('user u', 'u.id=b.uid')
  262. ->where(['b.id' => $id])
  263. ->field('u.id as uid, u.real_name,u.user_nickname,u.openid,b.id,b.order_sn,u.balance,b.money,b.credit,a.title,b.refund_credit,b.is_market,b.status')
  264. ->find();
  265. if (empty($info)) {
  266. $this->error("报名信息错误或不存在");
  267. }
  268. $status = isset($info['status']) ? $info['status'] : 0;
  269. $isMarket = isset($info['is_market']) ? $info['is_market'] : 0;
  270. if ($type == 1 && $isMarket == 1) {
  271. $this->error('报名订单已结算收益,无法全部退款');
  272. }
  273. $bMoney = isset($info['money']) ? floatval($info['money']) : 0.00;
  274. $bCredit = isset($info['credit']) ? floatval($info['credit']) : 0.00;
  275. $userId = isset($info['uid']) ? intval($info['uid']) : 0;
  276. // 退全款
  277. if ($type == 1) {
  278. if (!in_array($status, [2, 3])) {
  279. $this->error($status == 1 ? '报名订单未支付' : ($status == 4 ? '报名订单已取消' : '报名订单已退款处理'));
  280. }
  281. if ($money > $bMoney) {
  282. $this->error("退款金额超出支付金额");
  283. }
  284. $remark = $remark ? $remark : "平台活动报名费用退款{$money}元,报名单号:{$info['order_sn']}";
  285. } else if ($type == 2) {
  286. if($bCredit<=0){
  287. $this->error("没有可退款的守时金");
  288. }
  289. if ($money > $bCredit) {
  290. $this->error("退款金额超出支付金额");
  291. }
  292. $refundCredit = isset($info['refund_credit']) ? $info['refund_credit'] : 0;
  293. if ($refundCredit) {
  294. $this->error("该报名订单守时金已退款,无需再处理");
  295. }
  296. $remark = $remark ? $remark : "平台活动守时金退款{$money}元,报名单号:{$info['order_sn']}";
  297. } else {
  298. $this->error("抱歉当前退款类型不支持");
  299. }
  300. $orderSn = makeTradeNo('RF', $userId);
  301. $log = [
  302. 'order_sn' => $orderSn,
  303. 'money' => $money,
  304. 'type' => 6,
  305. 'pay_type' => 2,
  306. 'pay_money' => $money,
  307. 'user_id' => $userId,
  308. 'balance' => $info['balance'],
  309. 'remark' => $remark,
  310. 'created_at' => date('Y-m-d H:i:s'),
  311. 'status' => 1,
  312. ];
  313. $orderId = UserRechargeLog::insertGetId($log);
  314. if (!$orderId) {
  315. $this->error("创建退款订单失败");
  316. }
  317. // 打款
  318. Db::startTrans();
  319. $order = array(
  320. 'orderNo' => $log['order_sn'], //订单号
  321. 'openid' => $info['openid'],
  322. 'amount' => $money, //实际支付金额
  323. 'desc' => $remark, //描述
  324. );
  325. $result = Wechat::transferOrder($order);
  326. PRedis::set("cache:bookRefund:u_{$userId}_{$type}", ['info'=> $info,'result'=> $result], 3600);
  327. $resultCode = isset($result['result_code'])? strtoupper($result['result_code']) : '';
  328. $message = isset($result['message'])? $result['message'] : '';
  329. if ($resultCode == "SUCCESS") {
  330. $accountData = [
  331. 'type' => 9, //提现
  332. 'account_type' => 4, //余额类型
  333. 'change_type' => 1, //收入
  334. 'user_id' => $userId,
  335. 'money' => $money,
  336. 'balance' => $info['balance'],
  337. 'created_at' => date('Y-m-d H:i:s'),
  338. 'remark' => $remark,
  339. ];
  340. if (!AccountLog::insertGetId($accountData)) {
  341. Db::rollback();
  342. $this->error("账户明细处理失败");
  343. }
  344. // 更新退款订单状态
  345. UserRechargeLog::where(['id' => $orderId, 'type' => 6])->update(['status' => 2]);
  346. $data = ['remark' => $remark];
  347. if($type == 1){
  348. $data['status']= 5;
  349. }else{
  350. $data['refund_credit'] = 1;
  351. }
  352. Books::where(['id' => $id])->update($data);
  353. Db::commit();
  354. // 发送消息
  355. $checkTime = date('Y.m.d H:i');
  356. $title = isset($info['title']) ? '[' . $info['title'] . ']' : '';
  357. if ($info['openid']) {
  358. $name = $type == 1 ? '报名费已退还' : '守时金费用已退还';
  359. $params = [
  360. 'title' => "尊敬的用户,您报名参加的活动{$title}{$name},请您查收\n\n报名单号:\t{$info['order_sn']}",
  361. 'remark' => '感谢您对拾光的信任,点击查看退款明细',
  362. 'type' => 'refund',
  363. 'keywords' => [
  364. 'keyword1' => [
  365. 'value' => $log['order_sn'],
  366. 'color' => '#173177'
  367. ],
  368. 'keyword2' => [
  369. 'value' => $type == 1? '活动报名费退款' : '守时金退款',
  370. 'color' => '#173177'
  371. ],
  372. 'keyword3' => [
  373. 'value' => $money,
  374. 'color' => '#173177'
  375. ],
  376. 'keyword4' => [
  377. 'value' => $remark,
  378. 'color' => '#173177'
  379. ],
  380. ],
  381. 'url' => url('/weixin/account/index', '', '', true),
  382. ];
  383. wechat::sendTplMsg($info['openid'], $params);
  384. }
  385. $this->success('活动退款处理成功');
  386. } else {
  387. $this->error($message? $message : "打款处理失败,请核对订单后重试");
  388. }
  389. }
  390. /**
  391. * 报名列表审核
  392. *
  393. */
  394. public
  395. function shenhe()
  396. {
  397. $id = $this->request->param('id', 0, 'intval');
  398. //echo $id;die;
  399. //开始进行调用发送
  400. $result = Activity::bookConfirm($id, 3);
  401. if (is_array($result)) {
  402. $this->success("审核报名成功!", url("Books/index", ['id' => input('aid')]));
  403. } else {
  404. $this->success("审核报名成功!", url("Books/index", ['id' => input('aid')]));
  405. }
  406. }
  407. /**
  408. * 审核通过和审核不通过的弹框
  409. */
  410. public
  411. function goconfrom()
  412. {
  413. $this->assign("id", input('id'));
  414. return $this->fetch('confrom');
  415. }
  416. /**
  417. * 审核通过和审核不通过的弹框操作
  418. */
  419. public
  420. function doconfrom()
  421. {
  422. $param = $this->request->param();
  423. if (isset($param['yes']) && isset($param['id'])) {
  424. //开始进行调用成功发送
  425. $result = Activity::bookConfirm($param['id'], 3);
  426. if (is_array($result)) {
  427. echo 1;
  428. die;
  429. } else {
  430. echo 0;
  431. die;
  432. }
  433. }
  434. if (isset($param['no']) && isset($param['id'])) {
  435. //开始进行调用审核失败发送
  436. $result = Activity::bookConfirm($param['id'], 5, $param['noremark']);
  437. if (is_array($result)) {
  438. echo 1;
  439. die;
  440. } else {
  441. echo 0;
  442. die;
  443. }
  444. }
  445. }
  446. /**
  447. * 报名列表签到弹框
  448. *
  449. */
  450. public
  451. function gosignin()
  452. {
  453. $id = input('id');
  454. // $account_log = Db::name('account_log')
  455. // ->alias('alog')
  456. // ->join('user u','alog.user_id=u.id','left')
  457. // ->where(function (Query $query) use ($id) {
  458. // if ($id) {
  459. // $query->where('alog.id', $id);
  460. // }
  461. // })
  462. // ->field('alog.*,u.user_nickname')
  463. // ->find();
  464. $this->assign("id", $id);
  465. return $this->fetch('signin');
  466. }
  467. /**
  468. * 报名列表正常签到
  469. *
  470. */
  471. public
  472. function zhengchang()
  473. {
  474. $id = $this->request->param('id', 0, 'intval');
  475. $booksModel = new BooksModel();
  476. $data['id'] = $id;
  477. $data['is_signin'] = 2; //表示已正常签到
  478. $booksModel->isUpdate(true)->save($data);
  479. echo 1;
  480. die;
  481. // $this->success("正常签到成功!", url("Books/index",['id'=>$id]));
  482. }
  483. /**
  484. * 报名列表迟到签到
  485. *
  486. */
  487. public
  488. function chidao()
  489. {
  490. $id = $this->request->param('id', 0, 'intval');
  491. $booksModel = new BooksModel();
  492. $data['id'] = $id;
  493. $data['is_signin'] = 3; //表示已迟到签到
  494. $booksModel->isUpdate(true)->save($data);
  495. echo 1;
  496. die;
  497. // $this->success("迟到签到成功!", url("Books/index",['id'=>$id]));
  498. }
  499. /*
  500. *批量签到
  501. */
  502. public
  503. function allqiandao()
  504. {
  505. $params = input();
  506. $id = isset($params['id']) ? $params['id'] : 0;
  507. if (empty($id)) {
  508. $this->error('请先选择操作项!');
  509. }
  510. $id = is_array($id) ? implode(',', $id) : $id;
  511. $data['is_signin'] = 2; //表示已正常签到
  512. //Db::name('books')->where(['id' => ['in', $id]])->update($data);
  513. // $this->success($id);
  514. if (Db::name('books')->where('id', 'in', $id)->update($data)) {
  515. $this->success("批量签到成功!", '');
  516. } else {
  517. $this->error('批量签到失败!');
  518. }
  519. }
  520. /**
  521. *时间提醒显示
  522. *
  523. */
  524. public
  525. function reminder()
  526. {
  527. $actresult = Db::name('activity')
  528. ->field('alert_time1,alert_remark1,alert_time2,alert_remark2')
  529. ->where('id', input('id'))
  530. ->find();
  531. //显示是否进行了发送 第一次的显示
  532. $aid = input('id');
  533. $type = 2;
  534. $result1 = PRedis::get('activity:pushStatus:' . $aid . '_' . $type);
  535. if (!empty($result1)) { //代表已经发送了,输出1
  536. $result1 = 1;
  537. } else {
  538. $result1 = 0;
  539. }
  540. //显示是否进行了发送 第二次的显示
  541. $aid = input('id');
  542. $type = 1;
  543. $result2 = PRedis::get('activity:pushStatus:' . $aid . '_' . $type);
  544. if (!empty($result2)) { //代表已经发送了,输出1
  545. $result2 = 1;
  546. } else {
  547. $result2 = 0;
  548. }
  549. $this->assign('showf', $result1);
  550. $this->assign('showt', $result2);
  551. $this->assign('id', input('id'));
  552. $this->assign('actresult', $actresult);
  553. return $this->fetch('reminder');
  554. }
  555. /**
  556. * 提醒时间的保存1
  557. */
  558. public
  559. function savereminder1()
  560. {
  561. // input('id');
  562. $result = Db::name('activity')->where('id', input('id'))->update(['alert_time2' => input('alert_time1'), 'alert_remark2' => input('alert_remark1')]);
  563. echo $result;
  564. die;
  565. }
  566. /**
  567. * 提醒时间的保存2
  568. */
  569. public
  570. function savereminder2()
  571. {
  572. // input('id');
  573. $result = Db::name('activity')->where('id', input('id'))->update(['alert_time1' => input('alert_time2'), 'alert_remark1' => input('alert_remark2')]);
  574. echo $result;
  575. die;
  576. }
  577. /**
  578. * 第一次提醒时间发送 (代表前一天)
  579. */
  580. public
  581. function sendreminderfirst()
  582. {
  583. $aid = input('id');
  584. $type = 2;
  585. //开始进行调用发送
  586. $result = Activity::sendMessage($aid, $type);
  587. if (is_array($result)) {
  588. echo 1;
  589. die; //代表发送成功
  590. } else {
  591. echo lang($result);
  592. die; //代表发送失败
  593. }
  594. }
  595. /**
  596. * 第二次提醒时间发送(代表前几个小时)
  597. */
  598. public
  599. function sendremindertwo()
  600. {
  601. $aid = input('id');
  602. $type = 1;
  603. //开始进行调用发送
  604. $result = Activity::sendMessage($aid, $type);
  605. if (is_array($result)) {
  606. echo 1;
  607. die; //代表发送成功
  608. } else {
  609. echo lang($result);
  610. die; //代表发送失败
  611. }
  612. }
  613. /**
  614. *互动匹配
  615. *
  616. */
  617. public
  618. function matching()
  619. {
  620. $id = input('id');
  621. $result = Activity::heartMatch($id); //调用互动匹配
  622. if (is_array($result)) {
  623. $this->success('互动匹配发送成功');
  624. } else {
  625. $this->error(lang($result));
  626. }
  627. }
  628. /**
  629. *重新匹配
  630. *
  631. */
  632. public
  633. function twomatching()
  634. {
  635. $id = input('id');
  636. // 更新匹配状态
  637. $result0 = Db::name('activity')->where('id', $id)->update(['is_match' => 2]);
  638. $result = Activity::heartMatch($id); //调用互动匹配
  639. if (is_array($result)) {
  640. $this->success('互动匹配发送成功');
  641. } else {
  642. $this->error(lang($result));
  643. }
  644. }
  645. /**
  646. * 删除报名人,不是2,3状态的时候变成4
  647. */
  648. public
  649. function delbooks()
  650. {
  651. $aid = $this->request->param('aid', 0, 'intval');
  652. //代表线上的活动id,为单身推荐的活动下的用户
  653. if ($aid == 15) {
  654. //变更is_tuijian=0
  655. $result = Db::name('user')->where('id', input('uid'))->update(['is_tuijian' => 0]);
  656. if ($result) {
  657. Db::name('books')->where('id', input('id'))->update(['status' => 4]);
  658. $this->success("删除成功!", url("Books/index", ['id' => input('aid')]));
  659. } else {
  660. $this->error("删除失败!", url("Books/index", ['id' => input('aid')]));
  661. }
  662. } else {
  663. Db::name('books')->where('id', input('id'))->update(['status' => 4]);
  664. $this->success("删除成功!", url("Books/index", ['id' => input('aid')]));
  665. }
  666. }
  667. /*
  668. * PHPExcel导出报名用户列表
  669. */
  670. public
  671. function export()
  672. {
  673. $PHPExcel = new \PHPExcel();
  674. $PHPSheet = $PHPExcel->getActiveSheet(); //获得当前活动sheet的操作对象
  675. $PHPSheet->setTitle('报名人员列表'); /* 给当前sheet表设置名称及表头 */
  676. $PHPSheet->setCellValue('A1', '编号');
  677. $PHPSheet->setCellValue('B1', '姓名');
  678. $PHPSheet->setCellValue('C1', '年份');
  679. $PHPSheet->setCellValue('D1', '身高');
  680. $PHPSheet->setCellValue('E1', '学历');
  681. $PHPSheet->setCellValue('F1', '职位');
  682. $PHPSheet->setCellValue('G1', '手机号');
  683. $PHPSheet->setCellValue('H1', '微信号');
  684. $where = array('u.user_type' => 2);
  685. $field = 'b.book_num,`u`.`user_nickname`,u.real_name,YEAR(from_unixtime(`u`.`birthday`)) as birthday,up.height,up.education,up.occupation,u.mobile,up.wechat_code ';
  686. $dataList = Db::name('books')->alias('b')
  687. ->join('user u', 'b.uid=u.id', 'left')
  688. ->join('user_profile up', 'up.userid=u.id', 'left')
  689. ->where($where)
  690. ->where('b.status', 'neq', 1)
  691. ->where('b.status', 'neq', 4)
  692. ->where('b.status', 'neq', 5)
  693. ->where('b.aid', input('aid'))
  694. ->field($field)
  695. ->order("b.id DESC")
  696. ->select();
  697. //echo Db::name('user')->getLastSql();die;
  698. foreach ($dataList as $key => $item) {
  699. $key += 2;
  700. $PHPSheet->setCellValue('A' . $key, $item['book_num']);
  701. $PHPSheet->setCellValue('B' . $key, $this->guolv($this->filterEmoji($item['user_nickname'])));
  702. $PHPSheet->setCellValue('C' . $key, $item['birthday']);
  703. $PHPSheet->setCellValue('D' . $key, $item['height']);
  704. $PHPSheet->setCellValue('E' . $key, $this->xueli($item['education']));
  705. $PHPSheet->setCellValue('F' . $key, $item['occupation']);
  706. $PHPSheet->setCellValue('G' . $key, $item['mobile']);
  707. $PHPSheet->setCellValue('H' . $key, $item['wechat_code']);
  708. }
  709. $filename = "活动报名列表" . date('YmdHis') . ".xls";
  710. header("Pragma: public");
  711. header("Expires: 0");
  712. header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
  713. header("Content-Type:application/force-download");
  714. header("Content-Type:application/vnd.ms-execl");
  715. header("Content-Type:application/octet-stream");
  716. header("Content-Type:application/download");;
  717. header('Content-Disposition:attachment;filename=' . $filename . '');
  718. header("Content-Transfer-Encoding:binary");
  719. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel5');
  720. $PHPWriter->save('php://output');
  721. }
  722. /*
  723. * 过滤昵称的特效字符
  724. */
  725. public
  726. function filterEmoji($str)
  727. {
  728. $str = preg_replace_callback(
  729. '/./u',
  730. function (array $match) {
  731. return strlen($match[0]) >= 4 ? '' : $match[0];
  732. },
  733. $str);
  734. return $str;
  735. }
  736. //通过学历数号得到学历 学历:1-大专,2-本科,3-硕士,4-博士
  737. public
  738. function xueli($str)
  739. {
  740. switch ($str) {
  741. case '1':
  742. return '大专';
  743. break;
  744. case '2':
  745. return '本科';
  746. break;
  747. case '3':
  748. return '硕士';
  749. break;
  750. case '4':
  751. return '博士';
  752. break;
  753. }
  754. }
  755. //过滤字符串
  756. public function guolv($str){
  757. $str = str_replace('=', '等', $str);
  758. return $str;
  759. }
  760. //过滤字符串
  761. public function guolv2($str){
  762. $str = str_replace('`', '', $str);
  763. $str = str_replace('·', '', $str);
  764. $str = str_replace('~', '', $str);
  765. $str = str_replace('!', '', $str);
  766. $str = str_replace('!', '', $str);
  767. $str = str_replace('@', '', $str);
  768. $str = str_replace('#', '', $str);
  769. $str = str_replace('$', '', $str);
  770. $str = str_replace('¥', '', $str);
  771. $str = str_replace('%', '', $str);
  772. $str = str_replace('^', '', $str);
  773. $str = str_replace('……', '', $str);
  774. $str = str_replace('&', '', $str);
  775. $str = str_replace('*', '', $str);
  776. $str = str_replace('(', '', $str);
  777. $str = str_replace(')', '', $str);
  778. $str = str_replace('(', '', $str);
  779. $str = str_replace(')', '', $str);
  780. $str = str_replace('-', '', $str);
  781. $str = str_replace('_', '', $str);
  782. $str = str_replace('——', '', $str);
  783. $str = str_replace('+', '', $str);
  784. $str = str_replace('=', '', $str);
  785. $str = str_replace('|', '', $str);
  786. $str = str_replace('\\', '', $str);
  787. $str = str_replace('[', '', $str);
  788. $str = str_replace(']', '', $str);
  789. $str = str_replace('【', '', $str);
  790. $str = str_replace('】', '', $str);
  791. $str = str_replace('{', '', $str);
  792. $str = str_replace('}', '', $str);
  793. $str = str_replace(';', '', $str);
  794. $str = str_replace(';', '', $str);
  795. $str = str_replace(':', '', $str);
  796. $str = str_replace(':', '', $str);
  797. $str = str_replace('\'', '', $str);
  798. $str = str_replace('"', '', $str);
  799. $str = str_replace('“', '', $str);
  800. $str = str_replace('”', '', $str);
  801. $str = str_replace(',', '', $str);
  802. $str = str_replace(',', '', $str);
  803. $str = str_replace('<', '', $str);
  804. $str = str_replace('>', '', $str);
  805. $str = str_replace('《', '', $str);
  806. $str = str_replace('》', '', $str);
  807. $str = str_replace('.', '', $str);
  808. $str = str_replace('。', '', $str);
  809. $str = str_replace('/', '', $str);
  810. $str = str_replace('、', '', $str);
  811. $str = str_replace('?', '', $str);
  812. $str = str_replace('?', '', $str);
  813. return trim($str);
  814. }
  815. }