123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- <?php
- namespace app\operate\controller;
- use app\common\model\ActivityApplyItem;
- use app\common\model\BillApply;
- use app\common\model\StoreOrderRefund;
- use app\common\model\UserMessage;
- use app\common\service\OrderCallback;
- use app\common\service\UserSynth;
- use library\Controller;
- use think\Db;
- /**
- * 活动
- * Class ActivityApply
- * @package app\operate\controller
- */
- class ActivityApply extends Controller
- {
- protected $table = 'ActivityApply';
- /**
- * 列表
- * @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->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);
- $this->title = '报名记录';
- $where = [];
- $where[]= ['a.act_id','=' ,$id];
- $where[]= ['a.is_deleted','=' ,0];
- if($name) $where[]= ['u.name','like' ,'%'.$name.'%'];
- if($phone) $where[]= ['u.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];
- $this->qrarr= Db::name('activity_qrcode')->where('act_id',$id)->column('tg_param,id,phone','id');
- $query = $this->_query('activity_apply')
- ->alias('a')
- ->field('a.*,u.name user_name,u.headimg,u.phone')
- ->where($where)
- ->leftJoin('store_member u','u.id = a.user_id')
- ->order('a.id desc')->page();
- }
- /**
- * 编辑
- * @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'){
- $this->order_item = ActivityApplyItem::where(['o.apply_id'=>$data['id']])->alias('o')
- ->field('o.*,p.ladder_title,p.ladder_price')
- ->leftJoin('ActivityPrice p','p.id=o.price_id')
- ->select()->toArray();
- $this->data = $data;
- }
- if($this->request->get() && $this->request->action() == 'audit')
- {
- $data['refund_money'] = StoreOrderRefund::getToRefund($data['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
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function refund()
- {
- $id = input('post.id');
- \app\common\model\ActivityApply::where('id',$id)->update(['refund_state'=>2]);
- $order_info = \app\common\model\ActivityApply::where('id',$id)->find()->toArray();
- $act_title = \app\common\model\Activity::where('id',$order_info['act_id'])->value('title');
- $info_url = 'https://'.$_SERVER['HTTP_HOST'].'/dist/#/activity_order_info?id='.$id;
- $message = "您已取消《".$act_title."》活动订单,订单有效金额已原路返回,订单对应所有门票已失效";//."点击<a href=\"$info_url\">查看详情</a>";
- $res = \app\common\service\Activity::orderRefundMoney($id,$message);
- $res['code'] == 200 ? $this->success('操作成功') : $this->error($res['msg']);
- }
- /**
- * 退款审核
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function audit()
- {
- $this->title = '退款审核';
- $this->state_arr = ['未申请','审核中','同意退款','审核拒绝','退款异常','退款成功','取消申请'];
- if($this->request->isPost())
- {
- list($post)= [$this->request->post()];
- if($post['before_refund_state'] == 0) $this->error('订单未申请退款');
- if($post['before_refund_state'] == 6) $this->error('订单退款申请已取消');
- if($post['before_refund_state'] == 5) $this->error('订单已退款');
- if(!in_array($post['before_refund_state'],[1,4])) $this->error('无需重复审核');
- $order_info = \app\common\model\ActivityApply::where('id',$post['id'])->find()->toArray();
- $act_title = \app\common\model\Activity::where('id',$order_info['act_id'])->value('title');
- // 线下订单
- if($order_info['pay_type'] == 9) {
- \app\common\model\ActivityApply::where('id',$post['id'])->update(['refund_state'=>$post['refund_state']]);
- if($post['refund_state'] == 2) StoreOrderRefund::where(['order_id'=>$post['id']])->where('status','in','0,1,4')->update(['status'=>3]);
- if($post['refund_state'] == 3) StoreOrderRefund::where(['order_id'=>$post['id']])->where('status','in','0,1,4')->update(['status'=>2]);
- $this->success('操作成功');
- }
- switch ($post['refund_state'])
- {
- case 2:
- $info_url = 'https://'.$_SERVER['HTTP_HOST'].'/dist/#/activity_order_info?id='.$order_info['id'];
- $message = "您已取消《".$act_title."》活动订单,订单有效金额已原路返回,订单对应所有门票已失效";//."点击<a href=\"$info_url\">查看详情</a>";
- \app\common\model\ActivityApply::where('id',$post['id'])->update(['refund_state'=>2]);
- $res = \app\common\service\Activity::orderRefundMoney($post['id'],$message);
- $res['code'] == 200 ? $this->success('操作成功') : $this->error($res['msg']);
- break;
- case 3:
- \app\common\model\ActivityApply::where('id',$post['id'])->update(['refund_state'=>3]);
- StoreOrderRefund::where(['order_id'=>$post['id']])->where('status','in','0,1,4')->update(['status'=>2]);
- break;
- }
- $this->success('操作成功');
- }
- $this->_form($this->table, 'audit');
- }
- /**
- * 重新提醒
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function remind(){
- $order = \app\common\model\ActivityApply::where('id','in',input('id'))->select()->toArray();
- $ret_val = true;$msg='';
- Db::startTrans();
- try{
- foreach ($order as $k => $v){
- $order_info = $v;
- // 更改订单状态
- //\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 = 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';
- 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{
- 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('操作成功');
- }
- 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('暂无可以导出的数据');
- foreach ($data as $k=>&$v)
- {
- $v['order_source'] = $v['pay_type'] == 9 ? '转账订单':'线上订单';
- $v['pay_desc'] = $v['pay_state'] == 1 ? '已支付':'未支付';
- $item = Db::name('activity_apply_item')->where('apply_id',$v['id'])->find();
- $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 ? '需要审核':'不需要审核';
- }
- $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('i_extend', '答题模板'),
- );
- // return json($data);
- $this->phpExcelList($field,$data,'报名订单_'.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"); //输出到浏览器
- }
- }
|