Cron.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. <?php
  2. namespace Main\Lib;
  3. use Dever;
  4. class Cron
  5. {
  6. public function dao_order1_api()
  7. {
  8. # 根据订单的buy_id来确定生成的本数
  9. $order = Dever::db('journal/order')->getNew();
  10. $test = Dever::input('test');
  11. if ($test == 1) {
  12. print_r($order);die;
  13. }
  14. if ($order) {
  15. foreach ($order as $k => $v) {
  16. $info = Dever::db('act/order')->one(array('order_id' => $v['order_id']));
  17. if (!$info) {
  18. unset($v['id']);
  19. $v['status'] = 7;
  20. Dever::db('act/order')->insert($v);
  21. }
  22. }
  23. }
  24. return 'ok';
  25. }
  26. public function dao_order2_api()
  27. {
  28. # 根据订单的buy_id来确定生成的本数
  29. $id = Dever::input('product_id', 26);
  30. $where['product_id'] = $id;
  31. $where['status'] = 7;
  32. //$where['score_status'] = 1;
  33. $order_id = Dever::input('order_id');
  34. if ($order_id) {
  35. $where['order_id'] = $order_id;
  36. }
  37. $uid = Dever::input('uid');
  38. if ($uid) {
  39. $where['uid'] = $uid;
  40. }
  41. $order = Dever::db('act/order')->state($where);
  42. $test = Dever::input('test');
  43. if ($test == 1) {
  44. print_r($order);die;
  45. }
  46. if ($order) {
  47. foreach ($order as $k => $v) {
  48. $this->getpays($v['order_id']);
  49. }
  50. }
  51. return 'ok';
  52. }
  53. public function buy_code_api()
  54. {
  55. # 根据订单的buy_id来确定生成的本数
  56. $id = Dever::input('product_id', 26);
  57. $where['product_id'] = $id;
  58. $where['status'] = 2;
  59. //$where['score_status'] = 1;
  60. $order_id = Dever::input('order_id');
  61. if ($order_id) {
  62. $where['order_id'] = $order_id;
  63. }
  64. $uid = Dever::input('uid');
  65. if ($uid) {
  66. $where['uid'] = $uid;
  67. }
  68. $order = Dever::db('act/order')->state($where);
  69. $test = Dever::input('test');
  70. if ($test == 1) {
  71. print_r($order);die;
  72. }
  73. if ($order) {
  74. $db = Dever::load('code/lib/core');
  75. foreach ($order as $k => $v) {
  76. if ($v['type'] == 1 || $v['type'] == 3) {
  77. $v['code'] = '';
  78. $v['type'] = 3;
  79. $db->createCodeByOrder($v);
  80. }
  81. }
  82. }
  83. return 'ok';
  84. }
  85. public function buy_num_api()
  86. {
  87. # 根据订单的buy_id来确定生成的本数
  88. $id = Dever::input('product_id', 26);
  89. $where['product_id'] = $id;
  90. $where['status'] = 2;
  91. //$where['score_status'] = 1;
  92. $order_id = Dever::input('order_id');
  93. if ($order_id) {
  94. $where['order_id'] = $order_id;
  95. }
  96. $uid = Dever::input('uid');
  97. if ($uid) {
  98. $where['uid'] = $uid;
  99. }
  100. $order = Dever::db('act/order')->state($where);
  101. $test = Dever::input('test');
  102. if ($test == 1) {
  103. print_r($order);die;
  104. }
  105. if ($order) {
  106. $db = Dever::load('act/lib/num');
  107. $user = array();
  108. foreach ($order as $k => $v) {
  109. if ($v['type'] == 1 || $v['type'] == 3) {
  110. if ($v['buy_id'] > 0) {
  111. $num = Dever::db('journal/buy_num')->one($v['buy_id']);
  112. if ($num) {
  113. if (isset($user[$v['uid']]) && $user[$v['uid']]) {
  114. $user[$v['uid']]['num'] += $num['num'];
  115. } else {
  116. $user[$v['uid']] = array();
  117. $user[$v['uid']]['uid'] = $v['uid'];
  118. $user[$v['uid']]['id'] = $v['product_id'];
  119. $user[$v['uid']]['num'] = $num['num'];
  120. }
  121. }
  122. }
  123. }
  124. }
  125. foreach ($user as $k => $v) {
  126. $db->submit($v['id'], $v['uid'], $v['num'], false);
  127. }
  128. }
  129. return 'ok';
  130. }
  131. # 增加积分
  132. public function scores2_api()
  133. {
  134. //$where['start'] = Dever::maketime('2019-04-24 23:12:40');
  135. $where['start'] = Dever::maketime('2019-04-25 00:34:55');
  136. $where['end'] = Dever::maketime('2019-04-25 14:47:16');
  137. $where['score_type'] = 1;
  138. $where['action_id'] = Dever::input('action_id');
  139. $data = Dever::db('score/action_log')->getDataByDate($where);
  140. $test = Dever::input('test');
  141. if ($test == 1) {
  142. print_r($data);die;
  143. }
  144. if ($data) {
  145. foreach ($data as $k => $v) {
  146. Dever::load('score/lib/core.oper?log_id='.$v['id']);
  147. }
  148. }
  149. return $data;
  150. # 购买小刊
  151. /*
  152. $where['product_id'] = Dever::input('journal_id', 28);
  153. $where['type'] = 1;
  154. $where['status'] = 2;
  155. $data = Dever::db('journal/order')->state($where);
  156. $score = 20;
  157. if ($data) {
  158. foreach ($data as $k => $v) {
  159. # 计算该订单能加的积分数
  160. if ($v['buy_id'] && $v['buy_id'] > 0) {
  161. $buy = Dever::db('journal/buy_num')->one($data['buy_id']);
  162. if ($buy && $buy['num'] > 0) {
  163. $update_score = $score*$buy['num'];
  164. }
  165. }
  166. }
  167. }
  168. # 兑换小刊
  169. $where['product_id'] = Dever::input('journal_id', 28);
  170. $where['type'] = 2;
  171. $where['status'] = 2;
  172. $data = Dever::db('journal/order')->state($where);
  173. */
  174. }
  175. # 去重
  176. public function quchong_api()
  177. {
  178. # 购买小刊
  179. $id = Dever::input('product_id', 28);
  180. $where['product_id'] = $id;
  181. $where['status'] = 2;
  182. $order_id = Dever::input('order_id');
  183. if ($order_id) {
  184. $where['order_id'] = $order_id;
  185. }
  186. $uid = Dever::input('uid');
  187. if ($uid) {
  188. $where['uid'] = $uid;
  189. }
  190. $where['type'] = 2;
  191. //$where['score_status'] = 1;
  192. $order = Dever::db('journal/order')->state($where);
  193. if($order) {
  194. $user = array();
  195. foreach ($order as $k => $v) {
  196. if ($v['type'] == 2) {
  197. $key = $v['uid'] . '_' . $v['code'];
  198. if (!isset($user[$key])) {
  199. $user[$key] = $v;
  200. } else {
  201. Dever::db('journal/order')->update(array('where_id' => $v['id'], 'state' => 2));
  202. }
  203. }
  204. }
  205. }
  206. return 'ok';
  207. }
  208. # 重新计算排行榜
  209. public function pai4_api()
  210. {
  211. $id = Dever::input('product_id', 28);
  212. # 购买小刊
  213. $where['product_id'] = $id;
  214. $where['status'] = 2;
  215. $order_id = Dever::input('order_id');
  216. if ($order_id) {
  217. $where['order_id'] = $order_id;
  218. }
  219. $uid = Dever::input('uid');
  220. if ($uid) {
  221. $where['uid'] = $uid;
  222. }
  223. $where['type'] = array(1,3);
  224. //$where['score_status'] = 1;
  225. $order = Dever::db('journal/order')->getBuy($where);
  226. if ($order) {
  227. $user = array();
  228. foreach ($order as $k => $v) {
  229. $this->paiOrder1($v, $user);
  230. }
  231. }
  232. $test = Dever::input('test');
  233. if ($test == 1) {
  234. print_r($user);die;
  235. }
  236. # 重建积分排行
  237. foreach ($user as $k => $v) {
  238. print_r($v);
  239. $info = Dever::db('act/score')->one(array('uid' => $v['uid'], 'type' => 4, 'data_id' => $id));
  240. if (!$info) {
  241. $insert['uid'] = $v['uid'];
  242. $insert['type'] = 4;
  243. $insert['data_id'] = $id;
  244. $insert['score'] = $v['score'];
  245. Dever::db('act/score')->insert($insert);
  246. } else {
  247. $update['where_id'] = $info['id'];
  248. $update['uid'] = $v['uid'];
  249. $update['type'] = 4;
  250. $update['data_id'] = $id;
  251. $update['score'] = $v['score'] + $info['score'];
  252. Dever::db('act/score')->update($update);
  253. }
  254. }
  255. return 'ok';
  256. }
  257. public function paiOrder1($order, &$user)
  258. {
  259. if (!isset($user[$order['uid']])) {
  260. $user[$order['uid']] = array();
  261. $user[$order['uid']]['uid'] = $order['uid'];
  262. $user[$order['uid']]['score'] = 0;
  263. }
  264. $score = 0;
  265. if ($order['cash'] == 6) {
  266. $score = 20;
  267. }
  268. if ($order['cash'] == 60) {
  269. $score = 20*10;
  270. }
  271. if ($order['cash'] == 588) {
  272. $score = 20*100;
  273. }
  274. if ($order['cash'] == 1728) {
  275. $score = 20*300;
  276. }
  277. if ($order['cash'] == 3348) {
  278. $score = 20*600;
  279. }
  280. $user[$order['uid']]['score'] += $score;
  281. }
  282. # 重新计算排行榜
  283. public function pai3_api()
  284. {
  285. $id = Dever::input('product_id', 28);
  286. # 购买小刊
  287. $where['product_id'] = $id;
  288. $where['status'] = 2;
  289. $order_id = Dever::input('order_id');
  290. if ($order_id) {
  291. $where['order_id'] = $order_id;
  292. }
  293. $uid = Dever::input('uid');
  294. if ($uid) {
  295. $where['uid'] = $uid;
  296. }
  297. $where['type'] = 2;
  298. //$where['score_status'] = 1;
  299. $order = Dever::db('journal/order')->getBuy($where);
  300. $user = array();
  301. if ($order) {
  302. foreach ($order as $k1 => $v1) {
  303. $this->paiOrder($v1, $user);
  304. //Dever::db('journal/order')->update(array('where_id' => $v1['id'], 'score_status' => 2));
  305. }
  306. }
  307. $test = Dever::input('test');
  308. if ($test == 1) {
  309. print_r($user);die;
  310. }
  311. # 重建积分排行
  312. foreach ($user as $k => $v) {
  313. print_r($v);
  314. $info = Dever::db('act/score')->one(array('uid' => $v['uid'], 'type' => 4, 'data_id' => $id));
  315. if (!$info) {
  316. $insert['uid'] = $v['uid'];
  317. $insert['type'] = 4;
  318. $insert['data_id'] = $id;
  319. $insert['score'] = $v['score'];
  320. Dever::db('act/score')->insert($insert);
  321. } else {
  322. $update['where_id'] = $info['id'];
  323. $update['uid'] = $v['uid'];
  324. $update['type'] = 4;
  325. $update['data_id'] = $id;
  326. $update['score'] = $v['score'] + $info['score'];
  327. Dever::db('act/score')->update($update);
  328. }
  329. }
  330. return 'ok';
  331. }
  332. private function paiOrder($order, &$user)
  333. {
  334. if (!isset($user[$order['uid']])) {
  335. $user[$order['uid']] = array();
  336. $user[$order['uid']]['uid'] = $order['uid'];
  337. $user[$order['uid']]['score'] = 0;
  338. }
  339. if ($order['type'] <= 2) {
  340. # 购买小刊、兑换小刊增加积分
  341. if ($order['type'] == 1 && $order['buy_id'] > 0) {
  342. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  343. if ($buy) {
  344. $num = $buy['num'];
  345. $user[$order['uid']]['score'] += $num*20;
  346. }
  347. } elseif ($order['type'] == 2 && $order['code']) {
  348. $code = Dever::db('code/info')->one(array('code' => $order['code'], 'state' => 1, 'type' => 3));
  349. if ($code) {
  350. if ($code['order_id']) {
  351. $info = Dever::db('journal/order')->one(array('order_id' => $code['order_id'], 'status' => 2, 'type' => 3));
  352. if ($info) {
  353. $num = $code['product_num'];
  354. $user[$order['uid']]['score'] += $num*20;
  355. }
  356. } elseif ($code['product_num'] > 0) {
  357. $num = $code['product_num'];
  358. $user[$order['uid']]['score'] += $num*20;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. # 收回多余的兑换码
  365. public function deleteCode_api()
  366. {
  367. $order_id = Dever::input('order_id');
  368. if ($order_id) {
  369. $where['order_id'] = $order_id;
  370. }
  371. $where['product_id'] = 28;
  372. //$where['refund_status'] = 1;
  373. $where['type'] = 3;
  374. $data = Dever::db('journal/order')->state($where);
  375. $test = Dever::input('test');
  376. if ($test == 1) {
  377. print_r($data);
  378. }
  379. if ($data) {
  380. foreach ($data as $k => $v) {
  381. $this->deleteCodes($v);
  382. }
  383. }
  384. return 'ok';
  385. }
  386. private function deleteCodes($data)
  387. {
  388. # 获取该订单所能拥有的兑换码数
  389. $code_num = 1;
  390. $uid = $data['uid'];
  391. if ($data['buy_id'] > 0) {
  392. $buy = Dever::db('journal/buy_num')->one($data['buy_id']);
  393. $code_num = $buy['code'];
  394. }
  395. # 这个订单下所有码
  396. $code_where['order_id'] = $data['order_id'];
  397. $code_where['type'] = 4;
  398. $code = Dever::db('code/info')->getData($code_where);
  399. # code_num = 1
  400. # code = 21
  401. $test = Dever::input('test');
  402. if ($test == 1) {
  403. echo $code_num;
  404. print_r($code);die;
  405. }
  406. if ($code) {
  407. $i = 1;
  408. foreach ($code as $k => $v) {
  409. if ($i > $code_num) {
  410. Dever::db('code/info')->update(array('where_id' => $v['id'], 'state' => 2));
  411. }
  412. $i++;
  413. }
  414. }
  415. }
  416. public function refund_api()
  417. {
  418. $order_id = Dever::input('order_id');
  419. if ($order_id) {
  420. $where['order_id'] = $order_id;
  421. }
  422. $where['product_id'] = 28;
  423. $where['status'] = 5;
  424. $where['refund_status'] = 1;
  425. $data = Dever::db('journal/order')->state($where);
  426. $test = Dever::input('test');
  427. if ($test == 1) {
  428. print_r($data);die;
  429. }
  430. if ($data) {
  431. foreach ($data as $k => $v) {
  432. $this->refundScore($v);
  433. }
  434. }
  435. }
  436. private function refundScore($data)
  437. {
  438. $score = 0;
  439. if ($data['cash'] == 6) {
  440. $score = 20;
  441. }
  442. if ($data['cash'] == 60) {
  443. $score = 20*10;
  444. }
  445. if ($data['cash'] == 588) {
  446. $score = 20*100;
  447. }
  448. if ($data['cash'] == 1728) {
  449. $score = 20*300;
  450. }
  451. if ($data['cash'] == 3348) {
  452. $score = 20*600;
  453. }
  454. if ($score > 0) {
  455. if ($data['type'] == 1) {
  456. $where['uid'] = $data['uid'];
  457. $user = Dever::db('score/user')->one($where);
  458. if ($user) {
  459. $user_score = $user['score'] - $score;
  460. if ($user_score < 0) {
  461. $user_score = 0;
  462. }
  463. Dever::db('score/user')->update(array('where_id' => $user['id'], 'score' => $user_score));
  464. }
  465. $where['type'] = 4;
  466. $where['data_id'] = 28;
  467. $user = Dever::db('act/score')->one($where);
  468. if ($user) {
  469. $user_score = $user['score'] - $score;
  470. if ($user_score < 0) {
  471. $user_score = 0;
  472. }
  473. Dever::db('act/score')->update(array('where_id' => $user['id'], 'score' => $user_score));
  474. }
  475. } elseif ($data['type'] == 3) {
  476. $code_where['order_id'] = $data['order_id'];
  477. //$code_where['type'] = 1;
  478. $code_where['create_uid'] = $data['uid'];
  479. $code = Dever::db('code/info')->state($code_where);
  480. if ($code) {
  481. print_r($code);
  482. foreach ($code as $k => $v) {
  483. if ($v['type'] == 1) {
  484. Dever::db('code/info')->update(array('where_id' => $v['id'], 'type' => 4));
  485. } elseif ($v['type'] == 3) {
  486. $this->refundScoreCode($v);
  487. }
  488. }
  489. }
  490. }
  491. Dever::db('journal/order')->update(array('where_id' => $data['id'], 'refund_status' => 2));
  492. }
  493. print_r($data);
  494. print_r($score);
  495. echo "\r\n";
  496. return $score;
  497. }
  498. private function refundScoreCode($data)
  499. {
  500. if (isset($data['score']) && $data['score'] > 0) {
  501. $score = $data['score'];
  502. } elseif (isset($data['product_num']) && $data['product_num'] > 0) {
  503. $score = $data['product_num'] * 20;
  504. }
  505. if ($score > 0) {
  506. $where['uid'] = $data['uid'];
  507. $user = Dever::db('score/user')->one($where);
  508. if ($user) {
  509. $user_score = $user['score'] - $score;
  510. if ($user_score < 0) {
  511. $user_score = 0;
  512. }
  513. Dever::db('score/user')->update(array('where_id' => $user['id'], 'score' => $user_score));
  514. }
  515. $where['type'] = 4;
  516. $where['data_id'] = 28;
  517. $user = Dever::db('act/score')->one($where);
  518. if ($user) {
  519. $user_score = $user['score'] - $score;
  520. if ($user_score < 0) {
  521. $user_score = 0;
  522. }
  523. Dever::db('act/score')->update(array('where_id' => $user['id'], 'score' => $user_score));
  524. }
  525. }
  526. }
  527. public function pays_api()
  528. {
  529. $where['product_id'] = 28;
  530. $where['type'] = 3;
  531. $where['status'] = 1;
  532. $where['cron_status'] = 1;
  533. $data = Dever::db('journal/order')->state($where);
  534. if ($data) {
  535. foreach ($data as $k => $v) {
  536. $this->getpays($v['order_id']);
  537. Dever::db('journal/order')->update(array('where_id' => $v['id'], 'cron_status' => 2));
  538. }
  539. }
  540. }
  541. private function getpays($order_id)
  542. {
  543. $url = 'http://mapi.jstyle.cn/pay/pay/?api.search&order_id='.$order_id.'&account_id=1';
  544. Dever::curl($url);
  545. }
  546. public function unpay_api()
  547. {}
  548. public function activeEnd_api()
  549. {}
  550. #用户未支付电子刊情况下,未支付订单超过2小时后,发送一次唤回支付提醒
  551. public function unpay()
  552. {
  553. $time = 7200;
  554. $where['cdate'] = time() + $time;
  555. $where['note'] = 1;
  556. $where['type'] = '1,3';
  557. $data = Dever::db('journal/order')->getDataByTime($where);
  558. if ($data) {
  559. foreach ($data as $k => $v) {
  560. $user = Dever::db('passport/user')->one($v['uid']);
  561. if (!$user) {
  562. continue;
  563. }
  564. Dever::db('journal/order')->update(array('where_id' => $v['id'], 'note' => 2));
  565. $journal = Dever::db('journal/info')->one($v['product_id']);
  566. if (Dever::project('message')) {
  567. Dever::load('message/lib/data')->push(-1, $v['uid'], '支付提醒', '您订阅的'.$journal['name'].'尚未支付!', 11, $v['cate_id'], 1, Dever::load('act/lib/note')->push(4, $journal['id'], $journal['name']));
  568. }
  569. # 发送短消息
  570. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms')) {
  571. $send = array();
  572. $send['name'] = $journal['name'];
  573. //Dever::load('sms/api.send', 'note_live', $user['mobile'], $send);
  574. }
  575. # 发模板消息
  576. $wechat = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'type' => 1, 'system_id' => $v['cate_id']));
  577. if ($wechat && Dever::project('wechat_applet')) {
  578. $send['key'] = 'unbuy_journal';
  579. $send['project_id'] = $v['cate_id'];
  580. $send['touser'] = $wechat['openid'];
  581. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($v['uid']) . ',' . '4,' . $v['product_id'];
  582. $send['data'] = array
  583. (
  584. 'keyword1' => array('value' => $journal['name']),
  585. 'keyword2' => array('value' => $v['cash']),
  586. 'keyword3' => array('value' => '您订阅的'.$journal['name'].'尚未支付!'),
  587. );
  588. $send['data'] = json_encode($send['data']);
  589. $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 2, $v['cate_id']);
  590. if ($send['form_id']) {
  591. Dever::load('wechat_applet/msg.send', $send);
  592. }
  593. }
  594. }
  595. }
  596. return 'ok';
  597. }
  598. #电子杂志活动结束前5个时,向己有电子刊阅读权限的用户发送活动结束提醒
  599. public function activeEnd()
  600. {
  601. $time = 5*3600;
  602. $where['ends'] = time();
  603. $where['end'] = $where['ends'] + $time;
  604. $data = Dever::db('journal/active')->getDataByTime($where);
  605. //echo Dever::sql();die;
  606. $test = Dever::input('test');
  607. if ($test == 1) {
  608. print_r($data);die;
  609. }
  610. if ($data) {
  611. foreach ($data as $ks => $vs) {
  612. $journal = Dever::db('journal/info')->one($vs['info_id']);
  613. $subscribe = Dever::db('act/subscribe')->state(array('note' => 1, 'type' => 4, 'data_id' => $vs['info_id']));
  614. if ($subscribe) {
  615. foreach ($subscribe as $k => $v) {
  616. $user = Dever::db('passport/user')->one($v['uid']);
  617. if ($user) {
  618. Dever::db('act/subscribe')->update(array('where_id' => $v['id'], 'note' => 2));
  619. if (Dever::project('message')) {
  620. Dever::load('message/lib/data')->push(-1, $v['uid'], '活动结束提醒', '您参与的'.$journal['name'].'积分排行榜活动还有5小时就要结束了,想要冲榜赢奖品的要抓紧机会呀〜', 11, $journal['cate_id'], 1, Dever::load('act/lib/note')->push(4, $journal['id'], $journal['name']));
  621. }
  622. # 发送短消息
  623. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms')) {
  624. $send = array();
  625. $send['name'] = $journal['name'];
  626. //Dever::load('sms/api.send', 'note_live', $user['mobile'], $send);
  627. }
  628. # 发模板消息
  629. $wechat = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'type' => 1, 'system_id' => $journal['cate_id']));
  630. if ($wechat && Dever::project('wechat_applet')) {
  631. $send['key'] = 'service_end_note';
  632. $send['project_id'] = $journal['cate_id'];
  633. $send['touser'] = $wechat['openid'];
  634. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($v['uid']) . ',' . '4,' . $journal['id'];
  635. $send['data'] = array
  636. (
  637. 'keyword1' => array('value' => $journal['name']),
  638. 'keyword2' => array('value' => date('Y-m-d H:i', $vs['end'])),
  639. 'keyword3' => array('value' => '您参与的'.$journal['name'].'积分排行榜活动还有5小时就要结束了,想要冲榜赢奖品的要抓紧机会呀~'),
  640. );
  641. $send['data'] = json_encode($send['data']);
  642. $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 1, $journal['cate_id']);
  643. if (!$send['form_id']) {
  644. $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 2, $journal['cate_id']);
  645. }
  646. if ($send['form_id']) {
  647. Dever::load('wechat_applet/msg.send', $send);
  648. }
  649. }
  650. }
  651. }
  652. }
  653. }
  654. }
  655. return 'ok';
  656. }
  657. }