123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 会员中心
- */
- class Usercenter extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- //我的配套
- public function my_package(){
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 1,
- //'order.remain' => ['gt',0],
- 'order.is_gift' => 0,
- ];
- $list = Db::name('package_order')->alias('order')
- ->field('order.id,order.starttime,order.endtime,order.is_gift,order.remain,p.name,p.name_en')
- ->join('lesson_package p','order.package_id = p.id','LEFT')
- ->where($map)->order('order.remain desc,order.endtime asc')
- ->autopage()->select();
- $list = $this->list_lang($list,['name']);
- if(!empty($list)){
- foreach($list as $key => &$val){
- //日期
- if($this->lang == 'zh-cn'){
- $val['time_text'] = date('m月d,Y',$val['starttime']).'-'.date('m月d,Y',$val['endtime']);
- }else{
- $val['time_text'] = date('M d,Y',$val['starttime']).'-'.date('M d,Y',$val['endtime']);
- }
- //是否有延期按钮
- $val['expired'] = 0;
- if($val['endtime'] < time()){
- $val['expired'] = 1;
- }
- }
- }
- $this->success(1,$list);
- }
- //赠课记录
- public function package_gift(){
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 1,
- //'order.remain' => ['gt',0],
- 'order.is_gift' => 1,
- ];
- $list = Db::name('package_order')->alias('order')
- ->field('order.id,order.order_no,order.starttime,order.endtime,order.is_gift,order.sessions,order.remain,
- p.name as package_name,p.name_en as package_name_en')
- ->join('lesson_package p','order.package_id = p.id','LEFT')
- ->where($map)->order('order.remain desc,order.endtime asc')
- ->autopage()->select();
- $list = $this->list_lang($list,['name','package_name']);
- foreach($list as $key => &$order){
- //日期
- if($this->lang == 'zh-cn'){
- $order['showtime_text'] = date('m月d,Y',$order['starttime']).'-'.date('m月d,Y',$order['endtime']);
- }else{
- $order['showtime_text'] = date('M d,Y',$order['starttime']).'-'.date('M d,Y',$order['endtime']);
- }
-
- $order['remark'] = '购买套餐赠送';
- }
- $this->success(1,$list);
- }
- //上课记录,预约点了名的
- public function lesson_order_finish(){
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 20,//已点名
- 'order.usernumber_sign' => ['gt',0],
- ];
- $list = Db::name('lesson_order')->alias('order')
- ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,
- lesson.name,lesson.name_en,
- slot.starttime,slot.hours,slot.address,slot.coach_ids')
- ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
- ->join('lesson','order.lesson_id = lesson.id','LEFT')
- ->where($map)->order('order.finishtime desc')
- ->autopage()->select();
- $list = $this->list_lang($list,['name']);
- //准备教练数据
- $coach_list = Db::name('coach')->column('id,nickname');
- foreach($list as $key => &$order){
- //放入教练
- $coach_text = '';
- $coach_ids = explode(',',$order['coach_ids']);
- foreach($coach_ids as $coach_id){
- $coach_text .= $coach_list[$coach_id].',';
- }
- $order['coach_text'] = substr($coach_text,0,-1);
- //放入支付套餐
- if($order['paytype'] == 1){
- $package_order = Db::name('package_order')->alias('order')
- ->field('p.name,p.name_en,order.starttime,order.endtime')
- ->join('lesson_package p','order.package_id = p.id','LEFT')
- ->where('order.id',$order['package_order_id'])->find();
- $order['package_name'] = $package_order['name'];
- $order['package_name_en'] = $package_order['name_en'];
- $order['package_starttime'] = $package_order['starttime'];
- $order['package_endtime'] = $package_order['endtime'];
- $order['package_showtime_text'] = date('Y-m-d H:i',$package_order['starttime']).'-'.date('Y-m-d H:i',$package_order['endtime']);
- }
- //显示时间
- $order['showtime_text'] = date('Y-m-d H:i',$order['starttime']);
- }
- $list = $this->list_lang($list,['package_name']);
- $this->success(1,$list);
- }
- //取消记录
- public function lesson_order_cancel(){
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 30,//已取消
- ];
- $list = Db::name('lesson_order')->alias('order')
- ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,order.cancel_reason,
- lesson.name,lesson.name_en,
- slot.starttime,slot.hours,slot.address,slot.coach_ids')
- ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
- ->join('lesson','order.lesson_id = lesson.id','LEFT')
- ->where($map)->order('order.cancel_time desc')
- ->autopage()->select();
- $list = $this->list_lang($list,['name']);
- //准备教练数据
- $coach_list = Db::name('coach')->column('id,nickname');
- foreach($list as $key => &$order){
- //放入教练
- $coach_text = '';
- $coach_ids = explode(',',$order['coach_ids']);
- foreach($coach_ids as $coach_id){
- $coach_text .= $coach_list[$coach_id].',';
- }
- $order['coach_text'] = substr($coach_text,0,-1);
- //显示时间
- $order['showtime_text'] = date('Y-m-d H:i',$order['starttime']);
- //放入支付套餐
- /*if($order['paytype'] == 1){
- $package_order = Db::name('package_order')->alias('order')
- ->field('p.name,p.name_en,order.starttime,order.endtime')
- ->join('lesson_package p','order.package_id = p.id','LEFT')
- ->where('order.id',$order['package_order_id'])->find();
- $order['package_name'] = $package_order['name'];
- $order['package_name_en'] = $package_order['name_en'];
- $order['package_starttime'] = $package_order['starttime'];
- $order['package_endtime'] = $package_order['endtime'];
- }*/
- }
- //$list = $this->list_lang($list,['package_name']);
- $this->success(1,$list);
- }
- //取消售课预约单
- public function cancel_lesson_order(){
- $order_id = input('order_id',0);
- $map = [
- 'id' => $order_id,
- 'user_id' => $this->auth->id,
- ];
- $lesson_order = Db::name('lesson_order')->where($map)->find();
- if($lesson_order['order_status'] != 10){
- $this->error('此订单已无法取消');
- }
- //还有24小时上课,不能取消
- $slot = Db::name('lesson_slot')->where('id',$lesson_order['slot_id'])->find();
- if($slot['starttime'] - time() <= 86400){
- $this->error('距离上课时间不足24小时,不能取消');
- }
- Db::startTrans();
- //套餐给加回去
- if($lesson_order['paytype'] == 1){
- $package_order = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->lock(true)->find();
- $update = [
- 'remain' => $package_order['remain'] + $lesson_order['usernumber'],
- 'updatetime' => time(),
- ];
- $rs_remain = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->update($update);
- if($rs_remain === false){
- Db::rollback();
- $this->error('取消失败');
- }
- }
- //现金支付不给退,线下处理
- //取消预约单
- $update = [
- 'order_status' => 30,
- 'cancel_time' => time(),
- 'cancel_reason' => __('用户主动取消'),
- ];
- if($lesson_order['paytype'] == 1){
- $update['order_status'] = 40;
- }
- $rs = Db::name('lesson_order')->where($map)->update($update);
- if($rs === false){
- Db::rollback();
- $this->error('取消失败');
- }
- Db::commit();
- $this->success('取消完成');
- }
- //过期课程。就是过了上课时间,没签到的
- public function lesson_order_signout(){
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 20,//已点名
- 'order.usernumber_sign' => 0,//没签到的
- ];
- $list = Db::name('lesson_order')->alias('order')
- ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,
- lesson.name,lesson.name_en,
- slot.starttime,slot.hours,slot.address,slot.coach_ids')
- ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
- ->join('lesson','order.lesson_id = lesson.id','LEFT')
- ->where($map)->order('order.finishtime desc')
- ->autopage()->select();
- $list = $this->list_lang($list,['name']);
- //准备教练数据
- $coach_list = Db::name('coach')->column('id,nickname');
- foreach($list as $key => &$order){
- //放入教练
- $coach_text = '';
- $coach_ids = explode(',',$order['coach_ids']);
- foreach($coach_ids as $coach_id){
- $coach_text .= $coach_list[$coach_id].',';
- }
- $order['coach_text'] = substr($coach_text,0,-1);
- //放入支付套餐
- /*if($order['paytype'] == 1){
- $package_order = Db::name('package_order')->alias('order')
- ->field('p.name,p.name_en,order.starttime,order.endtime')
- ->join('lesson_package p','order.package_id = p.id','LEFT')
- ->where('order.id',$order['package_order_id'])->find();
- $order['package_name'] = $package_order['name'];
- $order['package_name_en'] = $package_order['name_en'];
- $order['package_starttime'] = $package_order['starttime'];
- $order['package_endtime'] = $package_order['endtime'];
- }*/
- }
- // $list = $this->list_lang($list,['package_name']);
- $this->success(1,$list);
- }
- //课程预约,即将到来3天,售课
- public function lesson_order_near(){
- $starttime = strtotime(date('Y-m-d')); //今天早上
- $todaytime = strtotime(date('Y-m-d')) + 86400*3 - 1; //后天晚上
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 10,
- 'slot.starttime' => ['BETWEEN',[$starttime,$todaytime]],
- ];
- $list = Db::name('lesson_order')->alias('order')
- ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,
- lesson.name,lesson.name_en,
- slot.starttime,slot.hours,slot.address,slot.coach_ids')
- ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
- ->join('lesson','order.lesson_id = lesson.id','LEFT')
- ->where($map)->order('order.finishtime desc')
- ->autopage()->select();
- $list = $this->list_lang($list,['name']);
- //准备教练数据
- $coach_list = Db::name('coach')->column('id,nickname');
- foreach($list as $key => &$order){
- //放入教练
- $coach_text = '';
- $coach_ids = explode(',',$order['coach_ids']);
- foreach($coach_ids as $coach_id){
- $coach_text .= $coach_list[$coach_id].',';
- }
- $order['coach_text'] = substr($coach_text,0,-1);
- //24小时内可以申请取消
- if($order['starttime'] - time() > 86400){
- $order['can_cancel'] = 1;
- }else{
- $order['can_cancel'] = 0;
- }
- //显示时间
- $order['showtime_text'] = date('Y-m-d H:i',$order['starttime']);
- //放入支付套餐
- /*if($order['paytype'] == 1){
- $package_order = Db::name('package_order')->alias('order')
- ->field('p.name,p.name_en,order.starttime,order.endtime')
- ->join('lesson_package p','order.package_id = p.id','LEFT')
- ->where('order.id',$order['package_order_id'])->find();
- $order['package_name'] = $package_order['name'];
- $order['package_name_en'] = $package_order['name_en'];
- $order['package_starttime'] = $package_order['starttime'];
- $order['package_endtime'] = $package_order['endtime'];
- }*/
- }
- //$list = $this->list_lang($list,['package_name']);
- $this->success(1,$list);
- }
- //课程预约,预约记录,售课
- public function lesson_order(){
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 10
- ];
- $list = Db::name('lesson_order')->alias('order')
- ->field('order.id,order.order_amount,order.paytype,order.package_order_id,order.package_remark,
- lesson.name,lesson.name_en,
- slot.starttime,slot.hours,slot.address,slot.coach_ids')
- ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
- ->join('lesson','order.lesson_id = lesson.id','LEFT')
- ->where($map)->order('order.finishtime desc')
- ->autopage()->select();
- $list = $this->list_lang($list,['name']);
- //准备教练数据
- $coach_list = Db::name('coach')->column('id,nickname');
- foreach($list as $key => &$order){
- //放入教练
- $coach_text = '';
- $coach_ids = explode(',',$order['coach_ids']);
- foreach($coach_ids as $coach_id){
- $coach_text .= $coach_list[$coach_id].',';
- }
- $order['coach_text'] = substr($coach_text,0,-1);
- //显示时间
- $order['showtime_text'] = date('Y-m-d H:i',$order['starttime']);
- //放入支付套餐
- /*if($order['paytype'] == 1){
- $package_order = Db::name('package_order')->alias('order')
- ->field('p.name,p.name_en,order.starttime,order.endtime')
- ->join('lesson_package p','order.package_id = p.id','LEFT')
- ->where('order.id',$order['package_order_id'])->find();
- $order['package_name'] = $package_order['name'];
- $order['package_name_en'] = $package_order['name_en'];
- $order['package_starttime'] = $package_order['starttime'];
- $order['package_endtime'] = $package_order['endtime'];
- }*/
- }
- //$list = $this->list_lang($list,['package_name']);
- $this->success(1,$list);
- }
- //课程预约,即将到来,试课
- public function trylesson_order_near(){
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 10
- ];
- $list = Db::name('trylesson_order')->alias('order')
- ->field('order.id,order.order_amount,order.paytime,order.order_status,
- trylesson.name,trylesson.name_en')
- ->join('trylesson','order.trylesson_id = trylesson.id','LEFT')
- ->where($map)->order('order.paytime desc')
- ->autopage()->select();
- $list = $this->list_lang($list,['name']);
- foreach($list as $key => &$order){
- //显示时间
- $order['showtime_text'] = date('Y-m-d H:i',$order['paytime']);
- }
- $this->success(1,$list);
- }
- //课程预约,预约记录,试课
- public function trylesson_order(){
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => ['gt',10]
- ];
- $list = Db::name('trylesson_order')->alias('order')
- ->field('order.id,order.order_amount,order.paytime,order.order_status,
- trylesson.name,trylesson.name_en')
- ->join('trylesson','order.trylesson_id = trylesson.id','LEFT')
- ->where($map)->order('order.paytime desc')
- ->autopage()->select();
- $list = $this->list_lang($list,['name']);
- foreach($list as $key => &$order){
- //显示时间
- $order['showtime_text'] = date('Y-m-d H:i',$order['paytime']);
- }
- $this->success(1,$list);
- }
- //设置通知方式
- //可以转让的、延期的配套
- public function package_list(){
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 1,
- 'order.remain' => ['gt',0],
- ];
- $list = Db::name('package_order')->alias('order')
- ->field('order.id,order.starttime,order.endtime,order.is_gift,order.remain,
- p.name,p.name_en')
- ->join('lesson_package p','order.package_id = p.id','LEFT')
- ->where($map)->order('order.remain desc,order.endtime asc')
- ->select();
- $list = $this->list_lang($list,['name']);
- if(!empty($list)){
- foreach($list as $key => &$val){
- //日期
- if($this->lang == 'zh-cn'){
- $val['time_text'] = date('m月d,Y',$val['starttime']).'-'.date('m月d,Y',$val['endtime']);
- }else{
- $val['time_text'] = date('M d,Y',$val['starttime']).'-'.date('M d,Y',$val['endtime']);
- }
- //是否有延期按钮
- $val['expired'] = 0;
- if($val['endtime'] < time()){
- $val['expired'] = 1;
- }
- }
- }
- $this->success(1,$list);
- }
- //配套转让申请
- public function package_move(){
- $field = ['name','mobile','email','reason','reason_files','package_order_id','sessions','to_name','to_mobile','to_email','remark'];
- $data = request_post_hub($field);
- $data['user_id'] = $this->auth->id;
- $data['createtime'] = time();
- Db::name('package_move')->insertGetId($data);
- $this->success('申请成功,请等待审核');
- }
- //配套延期申请
- public function package_delay(){
- $field = ['name','mobile','email','package_order_id','delay_week','reason','remark','reason_files'];
- $data = request_post_hub($field);
- $data['user_id'] = $this->auth->id;
- $data['createtime'] = time();
- Db::name('package_delay')->insertGetId($data);
- $this->success('申请成功,请等待审核');
- }
- //可以申请退课的
- public function refund_lesson_order(){
- //试课单
- $map = [
- 'order.user_id' => $this->auth->id,
- 'order.order_status' => 10
- ];
- $list = Db::name('trylesson_order')->alias('order')
- ->field('order.id,order.order_amount,order.paytime,
- trylesson.name,trylesson.name_en')
- ->join('trylesson','order.trylesson_id = trylesson.id','LEFT')
- ->where($map)->order('order.paytime desc')
- ->select();
- $trylist = $this->list_lang($list,['name']);
- //售课单(已支付开课24小时内不能取消的,已点名实到人不足的),已取消只是个暂时状态,后台处理完会改成已退课
- $map = [
- 'order.user_id' => $this->auth->id,
- ];
- $map2 = '( (order.order_status = 10 ) or (order.order_status = 20 and order.usernumber_sign != order.usernumber) )';
- $list = Db::name('lesson_order')->alias('order')
- ->field('order.id,order.order_amount,
- lesson.name,lesson.name_en,
- slot.starttime,slot.hours,slot.endtime')
- ->join('lesson_slot slot','order.slot_id = slot.id','LEFt')
- ->join('lesson','order.lesson_id = lesson.id','LEFT')
- ->where($map)
- ->where($map2)
- ->order('order.createtime desc')
- ->select();
- $lesson = $this->list_lang($list,['name']);
- if(!empty($list)){
- foreach($lesson as $key => &$val){
- //日期
- if($this->lang == 'zh-cn'){
- $val['showtime_text'] = date('m月d,Y',$val['starttime']).'-'.date('m月d,Y',$val['endtime']);
- }else{
- $val['showtime_text'] = date('M d,Y',$val['starttime']).'-'.date('M d,Y',$val['endtime']);
- }
- }
- }
- //
- $result = [
- 'trylesson' => $trylist,
- 'lesson' => $lesson,
- ];
- $this->success(1,$result);
- }
- //课时退课申请
- public function order_refund(){
- $field = ['name','mobile','email','order_table','order_id','remark','reason_files'];
- $require = ['order_table','order_id'];
- $data = request_post_hub($field,$require);
- $data['user_id'] = $this->auth->id;
- $data['createtime'] = time();
- //冗余订单号,售课=1,试课=2
- if($data['order_table'] == 1){
- $data['order_no'] = Db::name('lesson_order')->where('id',$data['order_id'])->value('order_no');
- }else{
- $data['order_no'] = Db::name('trylesson_order')->where('id',$data['order_id'])->value('order_no');
- }
- Db::name('order_refund')->insertGetId($data);
- $this->success('申请成功,请等待审核');
- }
- //公司团建活动信息
- public function company_apply(){
- $field = ['name','mobile','email','company_name','company_type','remark'];
- $data = request_post_hub($field);
- $data['user_id'] = $this->auth->id;
- $data['createtime'] = time();
- Db::name('company_apply')->insertGetId($data);
- $this->success('申请成功,请等待审核');
- }
- }
|