Plantask.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use app\common\library\Email;
  6. class Plantask extends Controller
  7. {
  8. //关于本文件里的计划任务
  9. //只有 public 方法,auto_开头的才是计划任务,其他private 方法都是工具方法
  10. ////////////////////////////////////////下面都是计划任务方法///////////////////////////////////////////////////////////////
  11. //明天有课,通知。计划任务10分钟执行一次
  12. public function auto_lesson_slot_notice(){
  13. $starttime = strtotime(date('Y-m-d')) + 86400;
  14. $endtime = $starttime + 86399;
  15. $map = [
  16. 'status' => 0,
  17. 'starttime' => ['BETWEEN',[$starttime,$endtime]],
  18. 'notice_status' => 0,
  19. ];
  20. $task_list = Db::name('lesson_slot')->where($map)->order('starttime asc')->limit(1)->select();
  21. if(empty($task_list)){
  22. echo 'empty';
  23. exit;
  24. }
  25. foreach($task_list as $slot){
  26. //这节课时,任务完成
  27. $update = [
  28. 'notice_status' => 1,
  29. ];
  30. Db::name('lesson_slot')->where('id',$slot['id'])->update($update);
  31. //找出这节课时的预约单
  32. $map = [
  33. 'order.order_status' => 10,
  34. 'order.slot_id' => $slot['id'],
  35. 'order.jointype' => 1, //预约类型:1=预约,2=候补
  36. ];
  37. $order_list = Db::name('lesson_order')->alias('order')
  38. ->field('lesson.name,lesson.name_en,user.firstname,user.lastname,user.email,user.whatsapp')
  39. ->join('user','order.user_id = user.id','LEFT')
  40. ->join('lesson','order.lesson_id = lesson.id','LEFT')
  41. ->where($map)->order('order.id asc')->select();
  42. if(!empty($order_list)){
  43. $coach_name = Db::name('coach')->where('id',$slot['coach_ids'])->value('nickname');
  44. //给这些预约单的用户发邮件
  45. try {
  46. foreach($order_list as $order){
  47. $message =
  48. 'Hi,'.$order['firstname']. ' ' .$order['lastname'].'!<br/>
  49. We are looking forward to seeing you at the following class tomorrow!<br/>
  50. Class:'.$order['name_en'].'<br/>
  51. Date: '.date('D l Y',$slot['starttime']).'<br/>
  52. Time: '.date('H:i a',$slot['starttime']).'<br/>
  53. Please arrive 10 minutes before the class timing to prepare for the harness fitting!<br/>
  54. We are located at 450 Alexandra Road, #02-01,<br/>
  55. Singapore 119960. For those who are driving, parking is available on level 2 of the building. For those who are taking public transport, the nearest mrt is Labrador Park MRT (7-10 minutes walk) and there is also a bus stop available just outside the building!<br/>
  56. We look forward to seeing you for an amazing session! ❤<br/>
  57. Best Regards,<br/>
  58. Elin Dance Studio<br/>
  59. <img src="'.config('website_url').'/assets/img/logo3.png" style="width:100px;height:100px">
  60. ';
  61. $obj = new Email();
  62. $result = $obj
  63. ->to($order['email'])
  64. ->subject('You have a class tomorrow!')
  65. ->message($message)
  66. ->send();
  67. $obj = '';
  68. //发whatsapp
  69. $parameters = [
  70. [
  71. 'type' => 'text',
  72. 'text' => $order['firstname'].' '.$order['lastname'],
  73. ],
  74. [
  75. 'type' => 'text',
  76. 'text' => $order['name_en'],
  77. ],
  78. [
  79. 'type' => 'text',
  80. 'text' => $coach_name,
  81. ],
  82. [
  83. 'type' => 'text',
  84. 'text' => date('D l Y',$slot['starttime']),
  85. ],
  86. [
  87. 'type' => 'text',
  88. 'text' => date('H:i a',$slot['starttime']),
  89. ],
  90. ];
  91. $this->whatapp($order['whatsapp'],'the_class_will_start_tomorrow','en_US',$parameters);
  92. }
  93. } catch (Exception $e) {
  94. }
  95. }
  96. }
  97. }
  98. //课程取消,通知。计划任务5分钟执行一次
  99. public function auto_lesson_slot_cancel(){
  100. exit;
  101. $map = [
  102. 'slot.status' => 30,
  103. 'slot.cancel_notice_status' => 0,
  104. ];
  105. $task_list = Db::name('lesson_slot')->alias('slot')
  106. ->field('slot.*,coach.nickname as coach_nickname,coach.email as coach_email,coach.whatsapp as coach_whatsapp,lesson.name_en as lesson_name_en')
  107. ->join('coach','slot.coach_ids = coach.id','LEFT')
  108. ->join('lesson','slot.lesson_id = lesson.id','LEFT')
  109. ->where($map)->order('slot.starttime asc')->limit(1)->select();
  110. if(empty($task_list)){
  111. echo 'empty';
  112. exit;
  113. }
  114. foreach($task_list as $slot){
  115. //这节课时,任务完成
  116. $update = [
  117. 'cancel_notice_status' => 1,
  118. ];
  119. Db::name('lesson_slot')->where('id',$slot['id'])->update($update);
  120. //找出这节课时的预约单
  121. $map = [
  122. 'order.slot_id' => $slot['id'],
  123. ];
  124. $order_list = Db::name('lesson_order')->alias('order')
  125. ->field('user.firstname,user.lastname,user.email,user.whatsapp')
  126. ->join('user','order.user_id = user.id','LEFT')
  127. ->where('(order.jointype = 1 and order.order_status = 10) or (order.jointype = 2 and order.order_status = 0)') //已支付的 或 候补单
  128. ->where($map)->order('order.id asc')->select();
  129. //把教练也加入到发送列表里
  130. $coach_sender = [
  131. 'firstname' => $slot['coach_nickname'],
  132. 'lastname' => '',
  133. 'email' => $slot['coach_email'],
  134. 'whatsapp' => $slot['coach_whatsapp'],
  135. ];
  136. $order_list[] = $coach_sender;
  137. if(empty($order_list)){
  138. continue;
  139. }
  140. //给这些预约单的用户发邮件
  141. try {
  142. foreach($order_list as $order){
  143. $message =
  144. 'Hi,'.$order['firstname']. ' ' .$order['lastname'].'!<br/>
  145. We regret to inform you that the following class has been cancelled.<br/>
  146. Class:'.$slot['lesson_name_en'].'<br/>
  147. Date: '.date('d F Y',$slot['starttime']).'<br/>
  148. Time: '.date('H:i a',$slot['starttime']).'<br/>
  149. Thank you for your kind understanding and look forward to seeing you in our studio soon!❤<br/>
  150. Best Regards,<br/>
  151. Elin Dance Studio<br/>
  152. <img src="'.config('website_url').'/assets/img/logo3.png" style="width:136px;height:115px">
  153. ';
  154. if(!empty($order['email'])){
  155. $obj = new Email();
  156. $result = $obj
  157. ->to($order['email'])
  158. ->subject('Class is Cancelled!')
  159. ->message($message)
  160. ->send();
  161. }
  162. $obj = '';
  163. //$coach_name = Db::name('coach')->where('id',$slot['coach_ids'])->value('nickname');
  164. //发whatsapp
  165. $parameters = [
  166. [
  167. 'type' => 'text',
  168. 'text' => $order['firstname'].' '.$order['lastname'],
  169. ],
  170. [
  171. 'type' => 'text',
  172. 'text' => $slot['lesson_name_en'],
  173. ],
  174. /* [
  175. 'type' => 'text',
  176. 'text' => $coach_name,
  177. ],*/
  178. [
  179. 'type' => 'text',
  180. 'text' => date('D l Y',$slot['starttime']) .' at '.date('H:i a',$slot['starttime']),
  181. ],
  182. ];
  183. if(!empty($order['whatsapp'])){
  184. $this->whatapp($order['whatsapp'],'class_cancelled','en_US',$parameters);
  185. }
  186. }
  187. } catch (Exception $e) {
  188. }
  189. }
  190. }
  191. //购买新套餐之后,通知。计划任务5分钟执行一次
  192. public function auto_after_buy_package(){
  193. $map = [
  194. 'order.order_status' => 1,
  195. 'order.buy_notice_status' => 0,
  196. 'order.is_gift' => 0,
  197. ];
  198. $task_list = Db::name('package_order')->alias('order')
  199. ->field('order.id,order.starttime,order.endtime,p.name,p.name_en,user.firstname,user.lastname,user.email,user.whatsapp')
  200. ->join('lesson_package p','order.package_id = p.id','LEFT')
  201. ->join('user','order.user_id = user.id','LEFT')
  202. ->where($map)->order('order.paytime asc')->limit(1)->select();
  203. if(empty($task_list)){
  204. echo 'empty';
  205. exit;
  206. }
  207. foreach($task_list as $order){
  208. //任务完成
  209. $update = [
  210. 'buy_notice_status' => 1,
  211. ];
  212. Db::name('package_order')->where('id',$order['id'])->update($update);
  213. try {
  214. $message =
  215. 'Hi,'.$order['firstname']. ' ' .$order['lastname'].'!<br/>
  216. Thank you for your purchase of the '.$order['name_en'].' plan!<br/>
  217. <b>Please note</b>: Plans that are 5 hours and above need to be activated by us! This is so that you can use up your current plans first (if any)!<br/>
  218. When you wish to activate, please send a WhatsApp message to 8879-9689 to activate your package to start booking classes.<br/>
  219. Once activated, your plan’s validity period will begin.<br/>
  220. You can view the unactivated packages in the app.<br/>
  221. We look forward to seeing you soon!❤<br/>
  222. Best Regards,<br/>
  223. Elin Dance Studio<br/>
  224. <img src="'.config('website_url').'/assets/img/logo3.png" style="width:136px;height:115px">
  225. ';
  226. //给这些用户发邮件
  227. $obj = new Email();
  228. $result = $obj
  229. ->to($order['email'])
  230. ->subject('Your plan purchase has been received!')
  231. ->message($message)
  232. ->send();
  233. $obj = '';
  234. //发whatsapp
  235. $parameters = [
  236. [
  237. 'type' => 'text',
  238. 'text' => $order['firstname'].' '.$order['lastname'],
  239. ],
  240. [
  241. 'type' => 'text',
  242. 'text' => $order['name_en'],
  243. ],
  244. /*[
  245. 'type' => 'text',
  246. 'text' => date('Y-m-d H:i',$order['starttime']),
  247. ],
  248. [
  249. 'type' => 'text',
  250. 'text' => date('Y-m-d H:i',$order['endtime']),
  251. ],
  252. [
  253. 'type' => 'text',
  254. 'text' => $order['firstname'].' '.$order['lastname'],
  255. ],*/
  256. ];
  257. $this->whatapp($order['whatsapp'],'buy_new_package','en_US',$parameters);
  258. } catch (Exception $e) {
  259. }
  260. }
  261. }
  262. //套餐将要到期,一个月,两周,一周,逐级通知,提醒三次。计划任务分别一小时执行一次
  263. public function auto_package_order_notice_mon(){
  264. $map = [
  265. 'order.order_status' => 1,
  266. 'order.use_status' => 1,
  267. 'order.remain' => ['gt',0],
  268. 'order.endtime' => ['lt',time()+(86400*30)],
  269. 'order.notice_status' => 0,
  270. ];
  271. $task_list = Db::name('package_order')->alias('order')
  272. ->field('order.id,order.endtime,p.name,p.name_en,order.remain,user.firstname,user.lastname,user.email,user.whatsapp')
  273. ->join('lesson_package p','order.package_id = p.id','LEFT')
  274. ->join('user','order.user_id = user.id','LEFT')
  275. ->where($map)->order('endtime asc')->limit(2)->select();
  276. if(empty($task_list)){
  277. echo 'empty';
  278. exit;
  279. }
  280. foreach($task_list as $order){
  281. //任务完成
  282. $update = [
  283. 'notice_status' => 1,//月通知已发送
  284. ];
  285. Db::name('package_order')->where('id',$order['id'])->update($update);
  286. try {
  287. $message =
  288. 'Hi,'.$order['firstname']. ' ' .$order['lastname'].'!<br/>
  289. We wanted to let you know that the following plan is set to expire in one month’s time!<br/>
  290. Plan: '.$order['name_en'].'<br/>
  291. Expiry Date: '.date('d F Y',$order['endtime']).'<br/>
  292. Please note that any unutilised hours will automatically be forfeited in the system. Book your next session now and continue working towards those amazing goals you have set for yourself!<br/>
  293. If you would like to sign up for another plan, you can contact us at 8879-9689 or check on the app!❤<br/>
  294. Best Regards,<br/>
  295. Elin Dance Studio<br/>
  296. <img src="'.config('website_url').'/assets/img/logo3.png" style="width:136px;height:115px">
  297. ';
  298. //给这些用户发邮件
  299. $obj = new Email();
  300. $result = $obj
  301. ->to($order['email'])
  302. ->subject('Your Membership Plan is Expiring in One Month’s Time!')
  303. ->message($message)
  304. ->send();
  305. $obj = '';
  306. //发whatsapp
  307. $parameters = [
  308. [
  309. 'type' => 'text',
  310. 'text' => $order['firstname'].' '.$order['lastname'],
  311. ],
  312. [
  313. 'type' => 'text',
  314. 'text' => $order['name_en'],
  315. ],
  316. [
  317. 'type' => 'text',
  318. 'text' => 'one month’s time',
  319. ],
  320. [
  321. 'type' => 'text',
  322. 'text' => date('D l Y',$order['endtime']),
  323. ],
  324. [
  325. 'type' => 'text',
  326. 'text' => ''.$order['remain'].'',
  327. ],
  328. ];
  329. $this->whatapp($order['whatsapp'],'package_expiration_reminder','en_US',$parameters);
  330. } catch (Exception $e) {
  331. }
  332. }
  333. }
  334. public function auto_package_order_notice_2week(){
  335. $map = [
  336. 'order.order_status' => 1,
  337. 'order.use_status' => 1,
  338. 'order.remain' => ['gt',0],
  339. 'order.endtime' => ['lt',time()+(86400*14)],
  340. 'order.notice_status' => 1,
  341. ];
  342. $task_list = Db::name('package_order')->alias('order')
  343. ->field('order.id,order.endtime,p.name,p.name_en,order.remain,user.firstname,user.lastname,user.email,user.whatsapp')
  344. ->join('lesson_package p','order.package_id = p.id','LEFT')
  345. ->join('user','order.user_id = user.id','LEFT')
  346. ->where($map)->order('endtime asc')->limit(2)->select();
  347. if(empty($task_list)){
  348. echo 'empty';
  349. exit;
  350. }
  351. foreach($task_list as $order){
  352. //任务完成
  353. $update = [
  354. 'notice_status' => 2,//2周通知已发送
  355. ];
  356. Db::name('package_order')->where('id',$order['id'])->update($update);
  357. try {
  358. $message =
  359. 'Hi,'.$order['firstname']. ' ' .$order['lastname'].'!<br/>
  360. We wanted to let you know that the following plan is set to expire in two week’s time!<br/>
  361. Plan: '.$order['name_en'].'<br/>
  362. Expiry Date: '.date('d F Y',$order['endtime']).'<br/>
  363. Please note that any unutilised hours will automatically be forfeited in the system. Book your next session now and continue working towards those amazing goals you have set for yourself!<br/>
  364. If you would like to sign up for another plan, you can contact us at 8879-9689 or check on the app!❤<br/>
  365. Best Regards,<br/>
  366. Elin Dance Studio<br/>
  367. <img src="'.config('website_url').'/assets/img/logo3.png" style="width:136px;height:115px">
  368. ';
  369. //给这些用户发邮件
  370. $obj = new Email();
  371. $result = $obj
  372. ->to($order['email'])
  373. ->subject('Your Membership Plan is Expiring in Two Week’s Time!')
  374. ->message($message)
  375. ->send();
  376. $obj = '';
  377. //发whatsapp
  378. $parameters = [
  379. [
  380. 'type' => 'text',
  381. 'text' => $order['firstname'].' '.$order['lastname'],
  382. ],
  383. [
  384. 'type' => 'text',
  385. 'text' => $order['name_en'],
  386. ],
  387. [
  388. 'type' => 'text',
  389. 'text' => '2 week’s time',
  390. ],
  391. [
  392. 'type' => 'text',
  393. 'text' => date('D l Y',$order['endtime']),
  394. ],
  395. [
  396. 'type' => 'text',
  397. 'text' => ''.$order['remain'].'',
  398. ],
  399. ];
  400. $this->whatapp($order['whatsapp'],'package_expiration_reminder','en_US',$parameters);
  401. } catch (Exception $e) {
  402. }
  403. }
  404. }
  405. public function auto_package_order_notice_1week(){
  406. $map = [
  407. 'order.order_status' => 1,
  408. 'order.use_status' => 1,
  409. 'order.remain' => ['gt',0],
  410. 'order.endtime' => ['lt',time()+(86400*7)],
  411. 'order.notice_status' => 2,
  412. ];
  413. $task_list = Db::name('package_order')->alias('order')
  414. ->field('order.id,order.endtime,p.name,p.name_en,order.remain,user.firstname,user.lastname,user.email,user.whatsapp')
  415. ->join('lesson_package p','order.package_id = p.id','LEFT')
  416. ->join('user','order.user_id = user.id','LEFT')
  417. ->where($map)->order('endtime asc')->limit(2)->select();
  418. if(empty($task_list)){
  419. echo 'empty';
  420. exit;
  421. }
  422. foreach($task_list as $order){
  423. //任务完成
  424. $update = [
  425. 'notice_status' => 3,//1周通知已发送
  426. ];
  427. Db::name('package_order')->where('id',$order['id'])->update($update);
  428. try {
  429. $message =
  430. 'Hi,'.$order['firstname']. ' ' .$order['lastname'].'!<br/>
  431. We wanted to let you know that the following plan is set to expire in one week’s time!<br/>
  432. Plan: '.$order['name_en'].'<br/>
  433. Expiry Date: '.date('d F Y',$order['endtime']).'<br/>
  434. Please note that any unutilised hours will automatically be forfeited in the system. Book your next session now and continue working towards those amazing goals you have set for yourself!<br/>
  435. If you would like to sign up for another plan, you can contact us at 8879-9689 or check on the app!❤<br/>
  436. Best Regards,<br/>
  437. Elin Dance Studio<br/>
  438. <img src="'.config('website_url').'/assets/img/logo3.png" style="width:136px;height:115px">
  439. ';
  440. //给这些用户发邮件
  441. $obj = new Email();
  442. $result = $obj
  443. ->to($order['email'])
  444. ->subject('Your Membership Plan is Expiring in One Week’s Time!')
  445. ->message($message)
  446. ->send();
  447. $obj = '';
  448. //发whatsapp
  449. $parameters = [
  450. [
  451. 'type' => 'text',
  452. 'text' => $order['firstname'].' '.$order['lastname'],
  453. ],
  454. [
  455. 'type' => 'text',
  456. 'text' => $order['name_en'],
  457. ],
  458. [
  459. 'type' => 'text',
  460. 'text' => '1 week’s time',
  461. ],
  462. [
  463. 'type' => 'text',
  464. 'text' => date('D l Y',$order['endtime']),
  465. ],
  466. [
  467. 'type' => 'text',
  468. 'text' => ''.$order['remain'].'',
  469. ],
  470. ];
  471. $this->whatapp($order['whatsapp'],'package_expiration_reminder','en_US',$parameters);
  472. } catch (Exception $e) {
  473. }
  474. }
  475. }
  476. /**
  477. * 复制本周的课程表
  478. */
  479. public function auto_slot_copyweek_old(){
  480. $week = date('w');
  481. if($week != 1){
  482. //exit;
  483. }
  484. //先查找 下周有没有数据
  485. $starttime = strtotime('this week Monday') + (86400*7);
  486. $endtime = $starttime + (86400*7);
  487. $check = Db::name('lesson_slot')->where('starttime','BETWEEN',[$starttime,$endtime])->find();
  488. if($check){
  489. echo '下周有数据了';
  490. exit;
  491. }
  492. echo '准备复制';
  493. //拿上周,复制到下周
  494. $starttime = strtotime('this week Monday') - (86400*7); // 获取本周一的时间戳
  495. $endtime = $starttime + (86400*7);
  496. $list = Db::name('lesson_slot')->where('is_show',1)->where('starttime','BETWEEN',[$starttime,$endtime])->order('starttime asc')->select();
  497. if(empty($list)){
  498. echo 'empty';
  499. exit;
  500. }
  501. foreach($list as $key => &$val){
  502. unset($val['id']);
  503. $val['starttime'] = $val['starttime'] + (86400*14);
  504. $val['endtime'] = $val['endtime'] + (86400*14);
  505. $val['bookednum'] = 0;
  506. $val['status'] = 0;
  507. $val['notice_status'] = 0;
  508. $val['finishtime'] = 0;
  509. $val['cancel_reason'] = '';
  510. $val['cancel_time'] = 0;
  511. $val['cancel_notice_status'] = 0;
  512. }
  513. Db::name('lesson_slot')->insertAll($list);
  514. echo '复制完成';
  515. //$this->success('已复制到下周');
  516. }
  517. //每两周一次
  518. //周一早上,复制本周+下周的课,到下下周+下下下周
  519. public function auto_slot_copyweek(){
  520. $week = date('w');
  521. if($week != 1){
  522. echo '不是周一';
  523. exit;
  524. }
  525. $check = Db::name('plantask')->where('key','auto_slot_copyweek')->whereTime('lasttime','week')->find();
  526. if($check){
  527. echo '本周执行过了';
  528. exit;
  529. }
  530. $check = Db::name('plantask')->where('key','auto_slot_copyweek')->whereTime('lasttime','last week')->find();
  531. if($check){
  532. echo '上周执行过了';
  533. exit;
  534. }
  535. //先查找 下周有没有数据
  536. /*$starttime = strtotime('this week Monday') + (86400*14);
  537. $endtime = $starttime + (86400*14);
  538. $check = Db::name('lesson_slot')->where('starttime','BETWEEN',[$starttime,$endtime])->find();
  539. if($check){
  540. echo '下下周和下下下周有数据了';
  541. exit;
  542. }*/
  543. echo '准备复制';
  544. //复制本周+下周的课
  545. $starttime = strtotime('this week Monday'); // 获取本周一的时间戳
  546. $endtime = $starttime + (86400*14);
  547. $list = Db::name('lesson_slot')->where('starttime','BETWEEN',[$starttime,$endtime])->order('starttime asc')->select();
  548. if(empty($list)){
  549. echo 'empty';
  550. exit;
  551. }
  552. //到下下周+下下下周
  553. foreach($list as $key => &$val){
  554. unset($val['id']);
  555. $val['starttime'] = $val['starttime'] + (86400*14);
  556. $val['endtime'] = $val['endtime'] + (86400*14);
  557. $val['bookednum'] = 0;
  558. $val['status'] = 0;
  559. $val['notice_status'] = 0;
  560. $val['finishtime'] = 0;
  561. $val['cancel_reason'] = '';
  562. $val['cancel_time'] = 0;
  563. $val['is_show'] = 0;
  564. $val['cancel_notice_status'] = 0;
  565. }
  566. Db::startTrans();
  567. $rs1 = Db::name('plantask')->where('key','auto_slot_copyweek')->update(['lasttime'=>time()]);
  568. if($rs1 === false){
  569. Db::rollback();
  570. $this->error('同步失败');
  571. }
  572. $rs2 = Db::name('lesson_slot')->insertAll($list);
  573. if(!$rs2){
  574. Db::rollback();
  575. $this->error('复制失败');
  576. }
  577. Db::commit();
  578. echo '复制完成';
  579. }
  580. /////////////////////////////////////////下面都是工具方法////////////////////////////////////////////////
  581. //发送whatapp消息的方法
  582. private function whatapp($receive_mobile,$template,$code,$parameters){
  583. if(empty($receive_mobile)){return true;}
  584. $token = config('site.whatsapp_token');
  585. //发送者
  586. $mobile_id = '337736419413019'; //Elin Dance Stuido 2:+65 8015 4154 , WhatsApp Business Account ID: 336509229537586
  587. //发送
  588. $url = 'https://graph.facebook.com/v19.0/'.$mobile_id.'/messages';
  589. $header = [
  590. 'Authorization: Bearer ' . $token,
  591. 'Content-Type: application/json',
  592. ];
  593. $body = [
  594. 'messaging_product' => 'whatsapp',
  595. 'recipient_type' => 'individual',
  596. 'to' => $receive_mobile,
  597. 'type' => 'template',
  598. 'template' => [
  599. 'name' => $template,
  600. 'language' => [
  601. 'code' => $code
  602. ],
  603. 'components' => [
  604. [
  605. 'type' => 'body',
  606. 'parameters' => $parameters
  607. ]
  608. ],
  609. ],
  610. ];
  611. $body = json_encode($body);
  612. $rs = curl_post($url,$body,$header);
  613. return true;
  614. }
  615. //结果集信息里,多个字段需要翻译
  616. private function list_lang($list,$field,$lang = ''){
  617. if(!$list || empty($list)){
  618. return $list;
  619. }
  620. foreach($list as $vo => $info){
  621. $list[$vo] = $this->info_lang($info,$field);
  622. }
  623. return $list;
  624. }
  625. //单条信息里,多个字段需要翻译
  626. private function info_lang($data,$field,$lang = ''){
  627. if(!$data || empty($data)){
  628. return $data;
  629. }
  630. foreach($data as $key => $val){
  631. if(in_array($key,$field)){
  632. if($lang == 'EN'){
  633. $data[$key] = $data[$key.'_en'];
  634. unset($data[$key.'_en']);
  635. }else{
  636. unset($data[$key.'_en']);
  637. }
  638. }
  639. }
  640. return $data;
  641. }
  642. }