Usercenter.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 会员中心
  7. */
  8. class Usercenter extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //我的配套
  13. public function my_package(){
  14. $map = [
  15. 'order.user_id' => $this->auth->id,
  16. 'order.order_status' => 1,
  17. //'order.remain' => ['gt',0],
  18. 'order.is_gift' => 0,
  19. ];
  20. $list = Db::name('package_order')->alias('order')
  21. ->field('order.id,order.starttime,order.endtime,order.is_gift,order.remain,p.name,p.name_en')
  22. ->join('lesson_package p','order.package_id = p.id','LEFT')
  23. ->where($map)->order('order.remain desc,order.endtime asc')
  24. ->autopage()->select();
  25. $list = $this->list_lang($list,['name']);
  26. if(!empty($list)){
  27. foreach($list as $key => &$val){
  28. //日期
  29. if($this->lang == 'zh-cn'){
  30. $val['time_text'] = date('m月d,Y',$val['starttime']).'-'.date('m月d,Y',$val['endtime']);
  31. }else{
  32. $val['time_text'] = date('M d,Y',$val['starttime']).'-'.date('M d,Y',$val['endtime']);
  33. }
  34. //是否有延期按钮
  35. $val['expired'] = 0;
  36. if($val['endtime'] < time()){
  37. $val['expired'] = 1;
  38. }
  39. }
  40. }
  41. $this->success(1,$list);
  42. }
  43. //赠课记录
  44. public function package_gift(){
  45. $map = [
  46. 'order.user_id' => $this->auth->id,
  47. 'order.order_status' => 1,
  48. //'order.remain' => ['gt',0],
  49. 'order.is_gift' => 1,
  50. ];
  51. $list = Db::name('package_order')->alias('order')
  52. ->field('order.id,order.order_no,order.starttime,order.endtime,order.is_gift,order.sessions,order.remain,
  53. p.name as package_name,p.name_en as package_name_en')
  54. ->join('lesson_package p','order.package_id = p.id','LEFT')
  55. ->where($map)->order('order.remain desc,order.endtime asc')
  56. ->autopage()->select();
  57. $list = $this->list_lang($list,['name','package_name']);
  58. foreach($list as $key => &$order){
  59. //日期
  60. if($this->lang == 'zh-cn'){
  61. $order['showtime_text'] = date('m月d,Y',$order['starttime']).'-'.date('m月d,Y',$order['endtime']);
  62. }else{
  63. $order['showtime_text'] = date('M d,Y',$order['starttime']).'-'.date('M d,Y',$order['endtime']);
  64. }
  65. $order['remark'] = '购买套餐赠送';
  66. }
  67. $this->success(1,$list);
  68. }
  69. //上课记录,预约点了名的
  70. public function lesson_order_finish(){
  71. $map = [
  72. 'order.user_id' => $this->auth->id,
  73. 'order.order_status' => 20,//已点名
  74. 'order.usernumber_sign' => ['gt',0],
  75. ];
  76. $list = Db::name('lesson_order')->alias('order')
  77. ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,
  78. lesson.name,lesson.name_en,
  79. slot.starttime,slot.hours,slot.address,slot.coach_ids')
  80. ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
  81. ->join('lesson','order.lesson_id = lesson.id','LEFT')
  82. ->where($map)->order('order.finishtime desc')
  83. ->autopage()->select();
  84. $list = $this->list_lang($list,['name']);
  85. //准备教练数据
  86. $coach_list = Db::name('coach')->column('id,nickname');
  87. foreach($list as $key => &$order){
  88. //放入教练
  89. $coach_text = '';
  90. $coach_ids = explode(',',$order['coach_ids']);
  91. foreach($coach_ids as $coach_id){
  92. $coach_text .= $coach_list[$coach_id].',';
  93. }
  94. $order['coach_text'] = substr($coach_text,0,-1);
  95. //放入支付套餐
  96. if($order['paytype'] == 1){
  97. $package_order = Db::name('package_order')->alias('order')
  98. ->field('p.name,p.name_en,order.starttime,order.endtime')
  99. ->join('lesson_package p','order.package_id = p.id','LEFT')
  100. ->where('order.id',$order['package_order_id'])->find();
  101. $order['package_name'] = $package_order['name'];
  102. $order['package_name_en'] = $package_order['name_en'];
  103. $order['package_starttime'] = $package_order['starttime'];
  104. $order['package_endtime'] = $package_order['endtime'];
  105. $order['package_showtime_text'] = date('Y-m-d H:i',$package_order['starttime']).'-'.date('Y-m-d H:i',$package_order['endtime']);
  106. }
  107. //显示时间
  108. $order['showtime_text'] = date('Y-m-d H:i',$order['starttime']);
  109. }
  110. $list = $this->list_lang($list,['package_name']);
  111. $this->success(1,$list);
  112. }
  113. //取消记录
  114. public function lesson_order_cancel(){
  115. $map = [
  116. 'order.user_id' => $this->auth->id,
  117. 'order.order_status' => 30,//已取消
  118. ];
  119. $list = Db::name('lesson_order')->alias('order')
  120. ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,order.cancel_reason,
  121. lesson.name,lesson.name_en,
  122. slot.starttime,slot.hours,slot.address,slot.coach_ids')
  123. ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
  124. ->join('lesson','order.lesson_id = lesson.id','LEFT')
  125. ->where($map)->order('order.cancel_time desc')
  126. ->autopage()->select();
  127. $list = $this->list_lang($list,['name']);
  128. //准备教练数据
  129. $coach_list = Db::name('coach')->column('id,nickname');
  130. foreach($list as $key => &$order){
  131. //放入教练
  132. $coach_text = '';
  133. $coach_ids = explode(',',$order['coach_ids']);
  134. foreach($coach_ids as $coach_id){
  135. $coach_text .= $coach_list[$coach_id].',';
  136. }
  137. $order['coach_text'] = substr($coach_text,0,-1);
  138. //显示时间
  139. $order['showtime_text'] = date('Y-m-d H:i',$order['starttime']);
  140. //放入支付套餐
  141. /*if($order['paytype'] == 1){
  142. $package_order = Db::name('package_order')->alias('order')
  143. ->field('p.name,p.name_en,order.starttime,order.endtime')
  144. ->join('lesson_package p','order.package_id = p.id','LEFT')
  145. ->where('order.id',$order['package_order_id'])->find();
  146. $order['package_name'] = $package_order['name'];
  147. $order['package_name_en'] = $package_order['name_en'];
  148. $order['package_starttime'] = $package_order['starttime'];
  149. $order['package_endtime'] = $package_order['endtime'];
  150. }*/
  151. }
  152. //$list = $this->list_lang($list,['package_name']);
  153. $this->success(1,$list);
  154. }
  155. //取消售课预约单
  156. public function cancel_lesson_order(){
  157. $order_id = input('order_id',0);
  158. $map = [
  159. 'id' => $order_id,
  160. 'user_id' => $this->auth->id,
  161. ];
  162. $lesson_order = Db::name('lesson_order')->where($map)->find();
  163. if($lesson_order['order_status'] != 10){
  164. $this->error('此订单已无法取消');
  165. }
  166. //还有24小时上课,不能取消
  167. $slot = Db::name('lesson_slot')->where('id',$lesson_order['slot_id'])->find();
  168. if($slot['starttime'] - time() <= 86400){
  169. $this->error('距离上课时间不足24小时,不能取消');
  170. }
  171. Db::startTrans();
  172. //套餐给加回去
  173. if($lesson_order['paytype'] == 1){
  174. $package_order = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->lock(true)->find();
  175. $update = [
  176. 'remain' => $package_order['remain'] + $lesson_order['usernumber'],
  177. 'updatetime' => time(),
  178. ];
  179. $rs_remain = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->update($update);
  180. if($rs_remain === false){
  181. Db::rollback();
  182. $this->error('取消失败');
  183. }
  184. }
  185. //现金支付不给退,线下处理
  186. //取消预约单
  187. $update = [
  188. 'order_status' => 30,
  189. 'cancel_time' => time(),
  190. 'cancel_reason' => __('用户主动取消'),
  191. ];
  192. if($lesson_order['paytype'] == 1){
  193. $update['order_status'] = 40;
  194. }
  195. $rs = Db::name('lesson_order')->where($map)->update($update);
  196. if($rs === false){
  197. Db::rollback();
  198. $this->error('取消失败');
  199. }
  200. Db::commit();
  201. $this->success('取消完成');
  202. }
  203. //过期课程。就是过了上课时间,没签到的
  204. public function lesson_order_signout(){
  205. $map = [
  206. 'order.user_id' => $this->auth->id,
  207. 'order.order_status' => 20,//已点名
  208. 'order.usernumber_sign' => 0,//没签到的
  209. ];
  210. $list = Db::name('lesson_order')->alias('order')
  211. ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,
  212. lesson.name,lesson.name_en,
  213. slot.starttime,slot.hours,slot.address,slot.coach_ids')
  214. ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
  215. ->join('lesson','order.lesson_id = lesson.id','LEFT')
  216. ->where($map)->order('order.finishtime desc')
  217. ->autopage()->select();
  218. $list = $this->list_lang($list,['name']);
  219. //准备教练数据
  220. $coach_list = Db::name('coach')->column('id,nickname');
  221. foreach($list as $key => &$order){
  222. //放入教练
  223. $coach_text = '';
  224. $coach_ids = explode(',',$order['coach_ids']);
  225. foreach($coach_ids as $coach_id){
  226. $coach_text .= $coach_list[$coach_id].',';
  227. }
  228. $order['coach_text'] = substr($coach_text,0,-1);
  229. //放入支付套餐
  230. /*if($order['paytype'] == 1){
  231. $package_order = Db::name('package_order')->alias('order')
  232. ->field('p.name,p.name_en,order.starttime,order.endtime')
  233. ->join('lesson_package p','order.package_id = p.id','LEFT')
  234. ->where('order.id',$order['package_order_id'])->find();
  235. $order['package_name'] = $package_order['name'];
  236. $order['package_name_en'] = $package_order['name_en'];
  237. $order['package_starttime'] = $package_order['starttime'];
  238. $order['package_endtime'] = $package_order['endtime'];
  239. }*/
  240. }
  241. // $list = $this->list_lang($list,['package_name']);
  242. $this->success(1,$list);
  243. }
  244. //课程预约,即将到来3天,售课
  245. public function lesson_order_near(){
  246. $starttime = strtotime(date('Y-m-d')); //今天早上
  247. $todaytime = strtotime(date('Y-m-d')) + 86400*3 - 1; //后天晚上
  248. $map = [
  249. 'order.user_id' => $this->auth->id,
  250. 'order.order_status' => 10,
  251. 'slot.starttime' => ['BETWEEN',[$starttime,$todaytime]],
  252. ];
  253. $list = Db::name('lesson_order')->alias('order')
  254. ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,
  255. lesson.name,lesson.name_en,
  256. slot.starttime,slot.hours,slot.address,slot.coach_ids')
  257. ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
  258. ->join('lesson','order.lesson_id = lesson.id','LEFT')
  259. ->where($map)->order('order.finishtime desc')
  260. ->autopage()->select();
  261. $list = $this->list_lang($list,['name']);
  262. //准备教练数据
  263. $coach_list = Db::name('coach')->column('id,nickname');
  264. foreach($list as $key => &$order){
  265. //放入教练
  266. $coach_text = '';
  267. $coach_ids = explode(',',$order['coach_ids']);
  268. foreach($coach_ids as $coach_id){
  269. $coach_text .= $coach_list[$coach_id].',';
  270. }
  271. $order['coach_text'] = substr($coach_text,0,-1);
  272. //24小时内可以申请取消
  273. if($order['starttime'] - time() > 86400){
  274. $order['can_cancel'] = 1;
  275. }else{
  276. $order['can_cancel'] = 0;
  277. }
  278. //显示时间
  279. $order['showtime_text'] = date('Y-m-d H:i',$order['starttime']);
  280. //放入支付套餐
  281. /*if($order['paytype'] == 1){
  282. $package_order = Db::name('package_order')->alias('order')
  283. ->field('p.name,p.name_en,order.starttime,order.endtime')
  284. ->join('lesson_package p','order.package_id = p.id','LEFT')
  285. ->where('order.id',$order['package_order_id'])->find();
  286. $order['package_name'] = $package_order['name'];
  287. $order['package_name_en'] = $package_order['name_en'];
  288. $order['package_starttime'] = $package_order['starttime'];
  289. $order['package_endtime'] = $package_order['endtime'];
  290. }*/
  291. }
  292. //$list = $this->list_lang($list,['package_name']);
  293. $this->success(1,$list);
  294. }
  295. //课程预约,预约记录,售课
  296. public function lesson_order(){
  297. $map = [
  298. 'order.user_id' => $this->auth->id,
  299. 'order.order_status' => 10
  300. ];
  301. $list = Db::name('lesson_order')->alias('order')
  302. ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,
  303. lesson.name,lesson.name_en,
  304. slot.starttime,slot.hours,slot.address,slot.coach_ids')
  305. ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
  306. ->join('lesson','order.lesson_id = lesson.id','LEFT')
  307. ->where($map)->order('order.finishtime desc')
  308. ->autopage()->select();
  309. $list = $this->list_lang($list,['name']);
  310. //准备教练数据
  311. $coach_list = Db::name('coach')->column('id,nickname');
  312. foreach($list as $key => &$order){
  313. //放入教练
  314. $coach_text = '';
  315. $coach_ids = explode(',',$order['coach_ids']);
  316. foreach($coach_ids as $coach_id){
  317. $coach_text .= $coach_list[$coach_id].',';
  318. }
  319. $order['coach_text'] = substr($coach_text,0,-1);
  320. //显示时间
  321. $order['showtime_text'] = date('Y-m-d H:i',$order['starttime']);
  322. //放入支付套餐
  323. /*if($order['paytype'] == 1){
  324. $package_order = Db::name('package_order')->alias('order')
  325. ->field('p.name,p.name_en,order.starttime,order.endtime')
  326. ->join('lesson_package p','order.package_id = p.id','LEFT')
  327. ->where('order.id',$order['package_order_id'])->find();
  328. $order['package_name'] = $package_order['name'];
  329. $order['package_name_en'] = $package_order['name_en'];
  330. $order['package_starttime'] = $package_order['starttime'];
  331. $order['package_endtime'] = $package_order['endtime'];
  332. }*/
  333. }
  334. //$list = $this->list_lang($list,['package_name']);
  335. $this->success(1,$list);
  336. }
  337. //课程预约,即将到来,试课
  338. public function trylesson_order_near(){
  339. $map = [
  340. 'order.user_id' => $this->auth->id,
  341. 'order.order_status' => 10
  342. ];
  343. $list = Db::name('trylesson_order')->alias('order')
  344. ->field('order.id,order.order_amount,order.paytime,order.order_status,
  345. trylesson.name,trylesson.name_en')
  346. ->join('trylesson','order.trylesson_id = trylesson.id','LEFT')
  347. ->where($map)->order('order.paytime desc')
  348. ->autopage()->select();
  349. $list = $this->list_lang($list,['name']);
  350. foreach($list as $key => &$order){
  351. //显示时间
  352. $order['showtime_text'] = date('Y-m-d H:i',$order['paytime']);
  353. }
  354. $this->success(1,$list);
  355. }
  356. //课程预约,预约记录,试课
  357. public function trylesson_order(){
  358. $map = [
  359. 'order.user_id' => $this->auth->id,
  360. 'order.order_status' => ['gt',10]
  361. ];
  362. $list = Db::name('trylesson_order')->alias('order')
  363. ->field('order.id,order.order_amount,order.paytime,order.order_status,
  364. trylesson.name,trylesson.name_en')
  365. ->join('trylesson','order.trylesson_id = trylesson.id','LEFT')
  366. ->where($map)->order('order.paytime desc')
  367. ->autopage()->select();
  368. $list = $this->list_lang($list,['name']);
  369. foreach($list as $key => &$order){
  370. //显示时间
  371. $order['showtime_text'] = date('Y-m-d H:i',$order['paytime']);
  372. }
  373. $this->success(1,$list);
  374. }
  375. //设置通知方式
  376. //可以转让的、延期的配套
  377. public function package_list(){
  378. $map = [
  379. 'order.user_id' => $this->auth->id,
  380. 'order.order_status' => 1,
  381. 'order.remain' => ['gt',0],
  382. ];
  383. $list = Db::name('package_order')->alias('order')
  384. ->field('order.id,order.starttime,order.endtime,order.is_gift,order.remain,
  385. p.name,p.name_en')
  386. ->join('lesson_package p','order.package_id = p.id','LEFT')
  387. ->where($map)->order('order.remain desc,order.endtime asc')
  388. ->select();
  389. $list = $this->list_lang($list,['name']);
  390. if(!empty($list)){
  391. foreach($list as $key => &$val){
  392. //日期
  393. if($this->lang == 'zh-cn'){
  394. $val['time_text'] = date('m月d,Y',$val['starttime']).'-'.date('m月d,Y',$val['endtime']);
  395. }else{
  396. $val['time_text'] = date('M d,Y',$val['starttime']).'-'.date('M d,Y',$val['endtime']);
  397. }
  398. //是否有延期按钮
  399. $val['expired'] = 0;
  400. if($val['endtime'] < time()){
  401. $val['expired'] = 1;
  402. }
  403. }
  404. }
  405. $this->success(1,$list);
  406. }
  407. //配套转让申请
  408. public function package_move(){
  409. $field = ['name','mobile','email','reason','reason_files','package_order_id','sessions','to_name','to_mobile','to_email','remark'];
  410. $data = request_post_hub($field);
  411. $data['user_id'] = $this->auth->id;
  412. $data['createtime'] = time();
  413. Db::name('package_move')->insertGetId($data);
  414. $this->success('申请成功,请等待审核');
  415. }
  416. //配套延期申请
  417. public function package_delay(){
  418. $field = ['name','mobile','email','package_order_id','delay_week','reason','remark','reason_files'];
  419. $data = request_post_hub($field);
  420. $data['user_id'] = $this->auth->id;
  421. $data['createtime'] = time();
  422. Db::name('package_delay')->insertGetId($data);
  423. $this->success('申请成功,请等待审核');
  424. }
  425. //可以申请退课的
  426. public function refund_lesson_order(){
  427. //试课单
  428. $map = [
  429. 'order.user_id' => $this->auth->id,
  430. 'order.order_status' => 10
  431. ];
  432. $list = Db::name('trylesson_order')->alias('order')
  433. ->field('order.id,order.order_amount,order.paytime,
  434. trylesson.name,trylesson.name_en')
  435. ->join('trylesson','order.trylesson_id = trylesson.id','LEFT')
  436. ->where($map)->order('order.paytime desc')
  437. ->select();
  438. $trylist = $this->list_lang($list,['name']);
  439. //售课单(已支付开课24小时内不能取消的,已点名实到人不足的),已取消只是个暂时状态,后台处理完会改成已退课
  440. $map = [
  441. 'order.user_id' => $this->auth->id,
  442. ];
  443. $map2 = '( (order.order_status = 10 ) or (order.order_status = 20 and order.usernumber_sign != order.usernumber) )';
  444. $list = Db::name('lesson_order')->alias('order')
  445. ->field('order.id,order.order_amount,
  446. lesson.name,lesson.name_en,
  447. slot.starttime,slot.hours,slot.endtime')
  448. ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
  449. ->join('lesson','order.lesson_id = lesson.id','LEFT')
  450. ->where($map)
  451. ->where($map2)
  452. ->order('order.createtime desc')
  453. ->select();
  454. $lesson = $this->list_lang($list,['name']);
  455. if(!empty($list)){
  456. foreach($lesson as $key => &$val){
  457. //日期
  458. if($this->lang == 'zh-cn'){
  459. $val['showtime_text'] = date('m月d,Y',$val['starttime']).'-'.date('m月d,Y',$val['endtime']);
  460. }else{
  461. $val['showtime_text'] = date('M d,Y',$val['starttime']).'-'.date('M d,Y',$val['endtime']);
  462. }
  463. }
  464. }
  465. //
  466. $result = [
  467. 'trylesson' => $trylist,
  468. 'lesson' => $lesson,
  469. ];
  470. $this->success(1,$result);
  471. }
  472. //课时退课申请
  473. public function order_refund(){
  474. $field = ['name','mobile','email','order_table','order_id','remark','reason_files'];
  475. $require = ['order_table','order_id'];
  476. $data = request_post_hub($field,$require);
  477. $data['user_id'] = $this->auth->id;
  478. $data['createtime'] = time();
  479. //冗余订单号,售课=1,试课=2
  480. if($data['order_table'] == 1){
  481. $data['order_no'] = Db::name('lesson_order')->where('id',$data['order_id'])->value('order_no');
  482. }else{
  483. $data['order_no'] = Db::name('trylesson_order')->where('id',$data['order_id'])->value('order_no');
  484. }
  485. Db::name('order_refund')->insertGetId($data);
  486. $this->success('申请成功,请等待审核');
  487. }
  488. //公司团建活动信息
  489. public function company_apply(){
  490. $field = ['name','mobile','email','company_name','company_type','remark'];
  491. $data = request_post_hub($field);
  492. $data['user_id'] = $this->auth->id;
  493. $data['createtime'] = time();
  494. Db::name('company_apply')->insertGetId($data);
  495. $this->success('申请成功,请等待审核');
  496. }
  497. }