where('is_show',1)->order('weigh desc')->autopage()->select(); $list = list_domain_image($list,['image']); $list = $this->list_lang($list,['name','content']); $this->success(1,$list); } //售课套餐列表 public function package_list(){ $lesson_id = input('lesson_id',0); //套餐列表 $list = Db::name('lesson_package')->alias('p') ->field('p.*,e.image') ->join('lesson e','p.lesson_id = e.id','LEFT') ->where('p.lesson_id',$lesson_id) ->where('p.is_show',1) ->order('p.weigh desc')->select(); $list = list_domain_image($list,['image']); $list = $this->list_lang($list,['name','validity','activeremark']); $this->success(1,$list); } //售课套餐详情 public function package_info(){ $package_id = input('package_id',0); //套餐详情 $list = Db::name('lesson_package')->alias('p') ->field('p.*,e.image') ->join('lesson e','p.lesson_id = e.id','LEFT') ->where('p.id',$package_id) ->order('p.weigh desc')->find(); $list = info_domain_image($list,['image']); $list = $this->info_lang($list,['name','validity','activeremark']); $this->success(1,$list); } //下单购买售课套餐 public function package_buy(){ $package_id = input('package_id',0); $package_info = Db::name('lesson_package')->where('id',$package_id)->find(); //套餐 $data = [ 'order_no' => createUniqueNo('P',$this->auth->id), 'user_id' => $this->auth->id, 'package_id' => $package_id, 'lesson_id' => $package_info['lesson_id'], 'sessions' => $package_info['sessions'], //'starttime' => , 'days' => $package_info['days'], //'endtime' => , 'price' => $package_info['price'], 'remain' => $package_info['sessions'], 'order_status'=> 0, 'paytime' => 0, 'createtime' => time(), 'updatetime' => 0, 'is_gift' => 0, ]; //如果有赠品 if(!empty($package_info['gift_lesson_id']) && !empty($package_info['gift_sessions'])){ $gift = $data; //订单号不换了 $gift['lesson_id'] = $package_info['gift_lesson_id']; $gift['sessions'] = $package_info['gift_sessions']; $gift['remain'] = $package_info['gift_sessions']; $gift['is_gift'] = 1; } //支付订单下单 $pay_order = []; $pay_order['user_id'] = $data['user_id']; $pay_order['out_trade_no'] = $data['order_no']; $pay_order['order_amount'] = $data['price']; $pay_order['createtime'] = $data['createtime']; $pay_order['pay_type'] = 'hitpay'; $pay_order['platform'] = 'app'; $pay_order['order_status'] = 0; $pay_order['table_name'] = 'package_order'; $pay_order['table_id'] = 0; $pay_order['args'] = ''; //入库 Db::startTrans(); $order_id = Db::name('package_order')->insertGetId($data); if(!$order_id){ $this->error('下单失败'); Db::rollback(); } $gift_order_id = Db::name('package_order')->insertGetId($gift); if(!$gift_order_id){ $this->error('下单失败'); Db::rollback(); } $pay_order['table_id'] = $order_id; $pay_order_id = Db::name('pay_order')->insertGetId($pay_order); if(!$pay_order_id){ $this->error('下单失败'); Db::rollback(); } Db::commit(); $this->success(1); } }