123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- <?php
- namespace app\operate\controller;
- use app\common\model\BillApply;
- use app\common\model\StoreOrderRefund;
- use app\common\model\UserLearn;
- use app\common\model\UserMessage;
- use app\common\service\OrderCallback;
- use app\common\service\UserSynth;
- use library\Controller;
- use think\Db;
- /**
- * 活动
- * Class ActivityApplyItem
- * @package app\operate\controller
- */
- class ActivityApplyItem extends Controller
- {
- protected $table = 'ActivityApplyItem';
- /**
- * 列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function index()
- {
- $this->status_list = [0=>'待审核',1=>'审核通过',2=>'审核拒绝'];
- $this->sh_status = $this->request->get('sh_status',-1);
- $id = $this->request->get('act_id');
- $name = $this->request->get('name');
- $phone = $this->request->get('phone');
- $qr_content = $this->request->get('qr_content');
- $sh_status = $this->request->get('sh_status',-1);
- $this->title = '报名记录';
- $where = [];
- $where[]= ['a.act_id','=' ,$id];
- $where[]= ['a.is_deleted','=' ,0];
- $where[]= ['o.pay_state','=' ,1];
- if($name) $where[]= ['a.name','like' ,'%'.$name.'%'];
- if($phone) $where[]= ['a.phone','like' ,'%'.$phone.'%'];
- if($qr_content) $where[]= ['a.qr_content','like' ,'%'.$phone.'%'];
- if(in_array($sh_status,[0,1,2])) $where[]= ['a.sh_status','=' ,$sh_status];
- $query = $this->_query('activity_apply_item')
- ->alias('a')
- ->field('a.*,u.headimg,o.order_no')
- ->where($where)
- ->leftJoin('store_member u','u.id = a.user_id')
- ->leftJoin('activity_apply o','o.id = a.apply_id')
- ->order('a.id desc')->page();
- }
- protected function _index_page_filter(array &$data)
- {
- foreach ($data as &$vo) {
- $vo['refund_status'] = StoreOrderRefund::where('order_type',1)->where('order_id',$vo['apply_id'])->where('item_id',$vo['id'])->value('status');
- }
- }
- /**
- * 编辑
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function edit()
- {
- $this->title = '编辑';
- $this->_form($this->table, 'form');
- }
- /**
- * 删除
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function del()
- {
- $this->_save($this->table, ['is_deleted' => '1']);
- }
- /**
- * 批量删除
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function remove()
- {
- $this->_save($this->table, ['is_deleted' => '1']);
- }
- /**
- * 表单数据处理
- * @auth true
- * @menu true
- * @param array $data
- */
- protected function _form_filter(&$data)
- {
- if($this->request->isGet() && $this->request->action() == 'edit')
- {
- if(isset($data['extend'])) $data['extend'] = json_decode($data['extend'],true);
- }
- if($this->request->isPost() && $this->request->action() == 'edit')
- {
- $ticket_info = \app\common\model\ActivityApplyItem::where('id',$data['id'])->find()->toArray();
- // 审核成功
- if($data['sh_status'] == 1)
- {
- if($data['sh_status'] == 1 && $ticket_info['sh_status'] !=1)
- {
- if(!$ticket_info['qr_code']) {
- $qrCode = new \Endroid\QrCode\QrCode();
- // 生成核销码
- $qr_content = $ticket_info['act_id'].'-'.$ticket_info['apply_id'].'-'.$ticket_info['id'];
- $qrCode->setText($qr_content);
- $qrCode->setSize(200);
- $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/code';
- $filename = $dir.'/'.$ticket_info['id'].'.png';
- $qrCode->writeFile($filename);
- $url='http://'.$_SERVER['SERVER_NAME']."/code/".$ticket_info['id'].'.png';
- \app\common\model\ActivityApplyItem::where('id',$ticket_info['id'])->update(['qr_code'=>$url,'qr_content'=>$qr_content]);
- }
- $act_title = \app\common\model\Activity::where('id',$ticket_info['act_id'])->value('title');
- $message = '您已成功报名"'.$act_title.'"';//点击<a href=\"$info_url\">查看详情及点子门票</a>";
- UserMessage::sendUserMessage($ticket_info['user_id'],'activity',1,1,0,$ticket_info['act_id'],$message,$ticket_info['id']);
- UserSynth::ticketSend($ticket_info['id']);
- //以下为新增内容
- $act = \app\common\model\Activity::where('id',$ticket_info['act_id'])->find();
- $nextYear = date('Y-m-d H:i:s', strtotime('+1 year'));
- //视频
- if($act['video_id'] && $act['video_id'] != 0){
- $arr = [
- 'user_id' => $ticket_info['user_id'],
- 'type' => 1,
- 'first_id' => $act['video_id'],
- 'second_id' => $act['video_item'],
- 'end_time' => $nextYear,
- 'end_int' => strtotime($nextYear)
- ];
- if(!UserLearn::where('type',1)->where('first_id',$act['datum_id'])->where('user_id',$ticket_info['user_id'])->find()) {
- UserLearn::create($arr);
- }
- }
- //资料
- if($act['datum_id'] && $act['datum_id'] != 0){
- $arr = [
- 'user_id' => $ticket_info['user_id'],
- 'type' => 2,
- 'first_id' => $act['datum_id'],
- 'second_id' => 0,
- 'end_time' => $nextYear,
- 'end_int' => strtotime($nextYear)
- ];
- if(!UserLearn::where('type',2)->where('first_id',$act['datum_id'])->where('user_id',$ticket_info['user_id'])->find()){
- UserLearn::create($arr);
- }
- }
- //图文
- if($act['article_id'] && $act['article_id'] != 0){
- $arr = [
- 'user_id' => $ticket_info['user_id'],
- 'type' => 3,
- 'first_id' => $act['article_id'],
- 'second_id' => $act['article_item'],
- 'end_time' => $nextYear,
- 'end_int' => strtotime($nextYear)
- ];
- if(!UserLearn::where('type',3)->where('first_id',$act['datum_id'])->where('user_id',$ticket_info['user_id'])->find()) {
- UserLearn::create($arr);
- }
- }
- //新增内容end
- }
- if($ticket_info['sh_status'] != 1 && $ticket_info['phone'] && $ticket_info['phone_pre'] == '86') {
- $act_info = \app\common\model\Activity::where('id',$ticket_info['act_id'])->find()->toArray();
- UserSynth::phoneMessageSend($ticket_info['phone'],1, [
- 'ActivityName'=>$act_info['title'],
- 'url'=>'dist/#/activity_ticket_info?id='.$ticket_info['id'],
- ]);
- $info_url = 'https://'.$_SERVER['HTTP_HOST'].'/dist/#/activity_ticket_info?id='.$ticket_info['id'];
- }
- }
- // 审核拒绝
- if($data['sh_status'] == 2) {
- $order_id = \app\common\model\ActivityApplyItem::where('id',$data['id'])->value('apply_id');
- $res = \app\common\service\Activity:: orderApplyRefund($order_id,$data['id'],2,1);
- $info_url = 'https://'.$_SERVER['HTTP_HOST'].'/dist/#/activity-detail?id='.$ticket_info['act_id'];
- $act_title = \app\common\model\Activity::where('id',$ticket_info['act_id'])->value('title');
- $message = '很抱歉,您报名的"'.$act_title.'"审核未通过';//,点击<a href=\"$info_url\">重新报名</a>";
- UserMessage::sendUserMessage($ticket_info['user_id'],'activity',1,1,0,$ticket_info['act_id'],$message,$ticket_info['id']);
- }
- }
- }
- /**
- * 确认收款
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function confirm()
- {
- $order_info = \app\common\model\ActivityApply::where('id',input('id'))->find()->toArray();
- $back_res = OrderCallback::activityOrderCallBack($order_info);// 支付完成后回调
- if(!$back_res['ret_val']) $this->error($back_res['msg']);
- $this->success('操作成功');
- }
- /**
- * 退款
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function refund()
- {
- $ticket_info = \app\common\model\ActivityApplyItem::where('id',input('id'))->find()->toArray();
- $refund_id = StoreOrderRefund::where('order_type',1)->where('order_id',$ticket_info['apply_id'])->where('item_id',$ticket_info['id'])->value('id');
- $back_res = \app\common\service\Activity:: orderRefund($refund_id);// 支付完成后回调
- if($back_res['code'] != 200) $this->error($back_res['msg']);
- $this->success('操作成功');
- }
- /**
- * 核销
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function hx()
- {
- if($this->request->isPost()) {
- $qr_content = input('post.qr_content');
- if(!$qr_content) $this->error('没有核销内容');
- $item_info = \app\common\model\ActivityApplyItem::where(['i.qr_content'=>$qr_content,'is_hx'=>0])
- ->alias('i')->field('i.is_hx,i.status,i.apply_id,i.is_deleted,a.status,a.cancel_state,a.pay_state,a.refund_state')
- ->leftJoin("ActivityApply a",'a.id = i.apply_id')->find();
- if(!$item_info) $this->error('没有找到核销记录');
- if($item_info->pay_state)$this->error('订单已取消');
- $refund_info = StoreOrderRefund::getRefundInfo($item_info['apply_id'],$item_info['id'],1);
- if(!empty($refund_info && in_array($refund_info['status'],[0,1,3,5])))$this->error('已申请退款');
- //if(!in_array($item_info->refund_state,[0,3]))$this->error('订单已申请退款');
- if(!in_array($item_info->status,[1]))$this->error('票状态异常');
- \app\common\model\ActivityApplyItem::where('id',$item_info['id'])->update(['is_hx'=>1,'ticket_status'=>1]);
- $this->success('核销成功');
- }
- $this->_form($this->table, 'hx');
- }
- public function export(){
- $this->order_status = $this->request->get('order_status',-1);
- $id = $this->request->get('act_id');
- $name = $this->request->get('name');
- $phone = $this->request->get('phone');
- $source_type = $this->request->get('source_type');
- $order_status = $this->request->get('order_status',-1);
- $tg_id = $this->request->get('tg_id',0);
- $where[]= ['a.act_id','=' ,$id];
- $where[]= ['a.is_deleted','=' ,0];
- if($name) $where[]= ['a.name','like' ,'%'.$name.'%'];
- if($phone) $where[]= ['a.phone','like' ,'%'.$phone.'%'];
- if($tg_id) $where[]= ['a.tg_id','=' ,$tg_id];
- if(in_array($order_status,[0,1,2])) $where[]= ['a.status','=' ,$order_status];
- if($source_type == 1) $where[]= ['a.pay_type','<>' ,9];
- if($source_type == 2) $where[]= ['a.pay_type','=' ,9];
- $data =Db::name('activity_apply')
- ->alias('a')
- ->field('a.*,u.name user_name,u.headimg,u.phone,t.phone tg_phone,t.qrcode,y.title act_title')
- ->where($where)
- ->leftJoin('store_member u','u.id = a.user_id')
- ->leftJoin('activity_qrcode t','t.id = a.tg_id')
- ->leftJoin('activity y','y.id = a.act_id')
- ->order('a.id desc')->select();
- if(empty($data)) $this->error('暂无可以导出的数据');
- $all = [];
- foreach ($data as $k=>&$v)
- {
- $items = Db::name('activity_apply_item')->where('apply_id',$v['id'])->select();
- foreach ($items as $k => $item){
- $v['order_source'] = $v['pay_type'] == 9 ? '转账订单':'线上订单';
- $v['pay_desc'] = $v['pay_state'] == 1 ? '已支付':'未支付';
- $v['i_name'] = $item['name'];
- $v['i_phone'] = $item['phone'];
- $v['i_email'] = $item['email'];
- $v['i_extend'] = '';
- $extend = json_decode($item['extend'],true);
- if($extend){
- foreach ($extend as $key => $val){
- $v['i_extend'] .= '问题:'.$val['title'].'
- ';
- if(isset($val['extend'])){
- $v['i_extend'] .= '选项:';
- foreach ($val['extend'] as $val1){
- $v['i_extend'] .= ''.$val1['item_title'].', ';
- }
- }else{
- $v['i_extend'] .= '回答:'.$val['value'].'
- ';
- }
- }
- }
- $v['i_extend'] = str_replace("\n", "\n", $v['i_extend']);
- // return json($v['i_extend']);
- $price = Db::name('activity_price')->where('id',$item['price_id'])->find();
- $v['ladder_title'] = $price['ladder_title'];
- if($v['pay_type'] == 1 || $v['pay_type'] == 2){
- $v['pay_type_text'] = 'H5';
- }else if($v['pay_type'] == 3 || $v['pay_type'] == 4){
- $v['pay_type_text'] = 'APP';
- }else if($v['pay_type'] == 5){
- $v['pay_type_text'] = '公众号';
- }else if($v['pay_type'] == 6 || $v['pay_type'] == 7){
- $v['pay_type_text'] = 'PC';
- }else{
- $v['pay_type_text'] = '未支付';
- }
- $v['is_sh'] = $price['is_sh'] == 1 ? '需要审核':'不需要审核';
- $v['is_hx'] = $item['is_hx'] == 1 ? '已核销':'未核销';
- $all[] = $v;
- }
- }
- $field=array(
- 'A' => array('order_no', '订单号'),
- 'B' => array('user_name', '联系人'),
- 'C' => array('phone', '电话'),
- 'D' => array('money','订单金额'),
- 'E' => array('num','人数'),
- 'F' => array('act_title','活动'),
- 'G' => array('order_source', '订单类型'),
- 'H' => array('pay_desc', '支付状态'),
- 'I' => array('tg_phone', '推广手机号'),
- 'J' => array('qrcode', '推广码链接'),
- 'K' => array('i_name', '姓名'),
- 'L' => array('i_phone', '手机号'),
- 'M' => array('i_email', '邮箱'),
- 'N' => array('ladder_title', '购票类型'),
- 'O' => array('is_sh', '是否审核'),
- 'P' => array('pay_type_text', '支付场景'),
- 'Q' => array('is_hx', '核销状态'),
- 'R' => array('i_extend', '答题模板'),
- );
- // return json($data);
- $this->phpExcelList($field,$all,'报名订单_'.date('Y-m-d H:i:s'));
- }
- public function phpExcelList($field=[],$list=[],$title='文件'){
- $PHPExcel=new \PHPExcel();
- $PHPSheet=$PHPExcel->getActiveSheet();
- $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
- foreach($list as $key=>$value)
- {
- foreach($field as $k=>$v){
- if($key == 0){
- $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
- }
- $i=$key+2;
- $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
- }
- }
- $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
- header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
- header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
- header('Cache-Control: max-age=0'); //禁止缓存
- $PHPWriter->save("php://output"); //输出到浏览器
- }
- /**
- * 重新提醒
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function remind(){
- $order = \app\common\model\ActivityApplyItem::where('id','in',input('id'))->group('apply_id')->select()->toArray();
- $ret_val = true;$msg='';
- Db::startTrans();
- try{
- foreach ($order as $k => $v){
- $order_info = \app\common\model\ActivityApply::where('id',$v['apply_id'])->find();
- // 更改订单状态
- //\app\common\model\ActivityApply::where('id',$order_info['id'])->update(['status'=>1,'pay_state'=>1,'pay_at'=>date('Y-m-d H:i:s')]);
- $item_list = \app\common\model\ActivityApplyItem::where('apply_id',$order_info['id'])->select()->toArray();
- $qrCode = new \Endroid\QrCode\QrCode();
- foreach ($item_list as $iv) {
- if($iv['sh_status'] == 1) {
- // 生成核销码
- $qr_content = $order_info['act_id'].'-'.$order_info['id'].'-'.$iv['id'];
- $qrCode->setText($qr_content);
- $qrCode->setSize(200);
- $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/code';
- $filename = $dir.'/'.$iv['id'].'.png';
- $qrCode->writeFile($filename);
- // return json($order_info);
- $url='http://'.$_SERVER['SERVER_NAME']."/code/".$iv['id'].'.png';
- \app\common\model\ActivityApplyItem::where('id',$iv['id'])->update(['status'=>1,'qr_code'=>$url,'qr_content'=>$qr_content]);
- $act_title = \app\common\model\Activity::where('id',$iv['act_id'])->value('title');
- $content = '您已成功报名"'.$act_title.'"';
- UserMessage::sendUserMessage($iv['user_id'],'apply',1,0,0,$iv['id'],$content,$iv['id']);
- UserSynth::ticketSend($iv['id']);
- }else{
- \app\common\model\ActivityApplyItem::where('id',$iv['id'])->update(['status'=>1]);
- }
- }
- // 活动订单发票记录修改
- BillApply::where(['order_type'=>3,'order_id'=>$order_info['id']])->update(['order_pay'=>1]);
- }
- //UserMessage::sendUserMessage($order_info['user_id'],'activity',1,0,0,$order_info['id'],'',$order_info['id']);
- Db::commit();
- }catch (\Exception $e){
- $ret_val = false;
- $msg = $e->getMessage();
- Db::rollback();
- }
- $this->success('操作成功');
- }
- }
|