|
@@ -0,0 +1,167 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller\coach;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+/**
|
|
|
+ * 售课
|
|
|
+ */
|
|
|
+class Lesson extends Api
|
|
|
+{
|
|
|
+ // 无需登录的接口,*表示全部
|
|
|
+ protected $noNeedLogin = [];
|
|
|
+ // 无需鉴权的接口,*表示全部
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+ //课时首页
|
|
|
+ public function slot_list(){
|
|
|
+
|
|
|
+ $date = input('date',date('Y-m-d'),'strtotime');
|
|
|
+ $where = [
|
|
|
+ 'slot.starttime' => ['BETWEEN',[$date,$date+86399]],
|
|
|
+ ];
|
|
|
+
|
|
|
+ //课时
|
|
|
+ $list = Db::name('lesson_slot')->alias('slot')
|
|
|
+ ->field('slot.*,lesson.name,lesson.name_en,lesson.image,lesson.price')
|
|
|
+ ->join('lesson','slot.lesson_id = lesson.id','LEFT')
|
|
|
+ ->where($where);
|
|
|
+
|
|
|
+ $list->where('find_in_set(:coach_ids,coach_ids)', ['coach_ids' => $this->auth->id]);
|
|
|
+
|
|
|
+ $list = $list->order('slot.starttime asc')->select();
|
|
|
+ if(empty($list)){
|
|
|
+ $this->success(1,[]);
|
|
|
+ }
|
|
|
+ $list = list_domain_image($list,['image']);
|
|
|
+ $list = $this->list_lang($list,['name']);
|
|
|
+
|
|
|
+
|
|
|
+ foreach($list as $key => &$slot){
|
|
|
+
|
|
|
+ //已报名数量,(包含已支付,已点名,没有冲突)
|
|
|
+ $pay_number = Db::name('lesson_order')->alias('order')
|
|
|
+ ->field('order.id,user.avatar,order.usernumber')
|
|
|
+ ->join('user','order.user_id = user.id','LEFT')
|
|
|
+ ->where('order.slot_id',$slot['id'])
|
|
|
+ ->where('order.order_status','IN',[10,20])
|
|
|
+ ->select();
|
|
|
+ $pay_number = list_domain_image($pay_number,['avatar']);
|
|
|
+
|
|
|
+ $slot['usernumber'] = array_sum(array_column($pay_number,'usernumber'));
|
|
|
+ $slot['useravatar'] = array_column($pay_number,'avatar');
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success(1,$list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //课时详情
|
|
|
+ public function slot_info(){
|
|
|
+ $slot_id = input('slot_id',0);
|
|
|
+
|
|
|
+ //课时
|
|
|
+ $info = Db::name('lesson_slot')->alias('slot')
|
|
|
+ ->field('slot.*,lesson.name,lesson.name_en,lesson.image,lesson.price')
|
|
|
+ ->join('lesson','slot.lesson_id = lesson.id','LEFT')
|
|
|
+ ->where('slot.id',$slot_id)->find();
|
|
|
+
|
|
|
+ $info = info_domain_image($info,['image']);
|
|
|
+ $info = $this->info_lang($info,['name']);
|
|
|
+
|
|
|
+ //已报名数量,(包含已支付,已点名,没有冲突)
|
|
|
+ $pay_number = Db::name('lesson_order')->alias('order')
|
|
|
+ ->field('order.id,user.avatar,order.usernumber,order.usernumber_sign')
|
|
|
+ ->join('user','order.user_id = user.id','LEFT')
|
|
|
+ ->where('order.slot_id',$info['id'])
|
|
|
+ ->where('order.order_status','IN',[10,20])
|
|
|
+ ->select();
|
|
|
+ $pay_number = list_domain_image($pay_number,['avatar']);
|
|
|
+
|
|
|
+ $info['usernumber'] = array_sum(array_column($pay_number,'usernumber'));
|
|
|
+
|
|
|
+ $info['user_list'] = $pay_number;
|
|
|
+
|
|
|
+
|
|
|
+ $this->success(1,$info);
|
|
|
+ }
|
|
|
+
|
|
|
+ //课时申请报名
|
|
|
+ public function slot_sign(){
|
|
|
+ $this->apiLimit();
|
|
|
+
|
|
|
+ $slot_id = input('slot_id',0,'intval');
|
|
|
+ $signdata = input('signdata','','htmlspecialchars_decode');
|
|
|
+ $signdata = json_decode($signdata,true);
|
|
|
+
|
|
|
+ //测试
|
|
|
+ /*$signdata = [
|
|
|
+ 6 => 1,
|
|
|
+ 7 => 2,
|
|
|
+ ];*/
|
|
|
+
|
|
|
+
|
|
|
+ //检查课时状态
|
|
|
+ $slot_info = Db::name('lesson_slot')->where('id',$slot_id)->find();
|
|
|
+ if($slot_info['status'] == 20){
|
|
|
+ $this->error('此课程已经点过名了');
|
|
|
+ }
|
|
|
+ if($slot_info['status'] != 0){
|
|
|
+ $this->error('此课程不能提交点名');
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查报名单数据
|
|
|
+ //逐个检查报名单,对比数量和状态。并保存
|
|
|
+ Db::startTrans();
|
|
|
+ $order_list = Db::name('lesson_order')->where('slot_id',$slot_id)->where('order_status',10)->order('id asc')->lock(true)->select();
|
|
|
+ if(count($order_list) != count($signdata)){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点名数据错误');
|
|
|
+ }
|
|
|
+ if(empty($order_list)){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('无人报名,请直接取消课程');
|
|
|
+ }
|
|
|
+ foreach($order_list as $order){
|
|
|
+ if(!isset($signdata[$order['id']])){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点名数据错误');
|
|
|
+ }
|
|
|
+ $usernumber_sign = $signdata[$order['id']];
|
|
|
+
|
|
|
+ if($usernumber_sign < 0 || $usernumber_sign > $order['usernumber']){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点名数据错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $update = [
|
|
|
+ 'usernumber_sign' => $usernumber_sign,
|
|
|
+ 'order_status' => 20,
|
|
|
+ 'finishtime' => time(),
|
|
|
+ ];
|
|
|
+ $rs_sign = Db::name('lesson_order')->where('id',$order['id'])->update($update);
|
|
|
+ if($rs_sign === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点名失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改课时状态
|
|
|
+ $update = [
|
|
|
+ 'status' => 20,
|
|
|
+ 'finishtime' => time(),
|
|
|
+ ];
|
|
|
+ $slot_rs = Db::name('lesson_slot')->where('id',$slot_id)->update($update);
|
|
|
+ if($slot_rs === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点名失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success('点名完成');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|