123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- <?php
- namespace app\api\controller;
- use addons\epay\library\Service;
- use app\admin\model\Method;
- use app\admin\model\method\Time;
- use app\admin\model\Order;
- use app\admin\model\Ordercode;
- use app\admin\model\Orderitem;
- use app\admin\model\Pingjia;
- use app\admin\model\Smsorder;
- use app\admin\model\Tzmoneyrecharge;
- use app\admin\model\Usercar;
- use app\admin\model\UserMoneyLog;
- use app\common\controller\Api;
- use EasyWeChat\Factory;
- use think\Db;
- use Yansongda\Pay\Pay;
- class Yorder extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- public function order_no(){
- $order_model=new Order();
- $order_id= input('order_id');
- $pay_type = input('pay_type');
- $order_new_no = order_no($this->auth->id);
- $order_model->isUpdate('true',['id'=>$order_id])->save(['order_no'=>$order_new_no,'pay_type'=>$pay_type]);
- $this->success('重新生成订单号',$order_id);
- }
- /**
- * 钓鱼下单
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function order_create(){
- $method_model =new Method();
- $order_no = order_no($this->auth->id);
- $data=input();
- // $data['item']=[['id'=>133,'title'=>'14:00-17:00','price'=>50,'type'=>1,'number'=>10],['id'=>2,'title'=>'女钓友福利','price'=>0,'type'=>2,'number'=>1]];
- // $data['user']=[['name'=>1,'phone'=>1223],['name'=>2,'phone'=>122],['name'=>3,'phone'=>110]];
- foreach ($data['item'] as &$d){
- if($d['type']==1){
- $time_model = new Time();
- // print_r($d);die;
- $time_info = $time_model->where('id',$d['id'])->find();
- if($time_info['is_set']==1){
- if($d['number']>$time_info['sale_num']){
- $this->error('所选时间段座位不够了');
- }
- }
- // print_r($d['number']);print_r($time_info['sale_num']);die;
- }
- }
- $method_info = $method_model->where('id',$data['method_id'])->field('type,show_images,moshi,user_id,yutang_id,yutang_name,eat_price,yajin')->find();
- $images = explode(',',$method_info['show_images']);
- $order_data = [
- 'user_id'=>$this->auth->id,
- 'order_no'=>$order_no,
- 'image'=>$images[0],
- 'yutang'=>$method_info['yutang_name'],
- 't_user_id'=>$method_info['user_id'],
- 'yutang_id'=>$method_info['yutang_id'],
- 'method_id'=>$data['method_id'],
- 'pay_type'=>$data['type'],
- 'item_money'=>$data['item_money'],
- 'wucan_money'=>$data['wucan_money'],
- 'yajin_money'=>$data['yajin_money'],
- 'youhui_money'=>config('site.reduction'),
- 'order_money'=>$data['order_money'],
- 'status'=>1,
- 'create_time'=>time(),
- 'number'=>$data['number'],
- 'type'=>$method_info['type'],
- 'moshi'=>$method_info['moshi'],
- 'phone'=>$this->auth->mobile,
- ];
- //zhifu
- Db::startTrans();
- try {
- $order_model = new Order();
- $order_id = $order_model->insertGetId($order_data);
- foreach ($data['item'] as $v){
- for ($i=0;$i<$v['number'];$i++){
- $ruchang_number='RC'.rand('000000','999999').$order_id;
- $code1 = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/index.php/api/writeoff/saoma'.'?'.'ruchang'.'='.$ruchang_number;
- $ruchang_code= 'code/ruchang/'.$ruchang_number.'.png';//图片路径名
- $ruchang_price = $v['price'];
- $this->code($code1,$ruchang_code);
- if($data['wucan_money']>0) {
- $wucan_number = 'WC'.rand('000000', '999999') . $order_id;
- $code2 = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/index.php/api/writeoff/saoma'.'?'.'wucan'.'='.$wucan_number;
- $wucan_code= 'code/wucan/'.$wucan_number.'.png';//图片路径名
- $wucan_price = $method_info['eat_price'];
- $this->code($code2,$wucan_code);
- }
- $yajin_number='YJ'.rand('000000','999999').$order_id;
- $code3 = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/index.php/api/writeoff/saoma'.'?'.'yajin'.'='.$yajin_number;
- $yajin_code= 'code/yajin/'.$yajin_number.'.png';//图片路径名
- $yajin_price = $method_info['yajin'];
- $this->code($code3,$yajin_code);
- $code_data =[
- 'order_id'=>$order_id,
- 'ruchang_number'=>$ruchang_number,
- 'ruchang_code'=>'/'.$ruchang_code,
- 'ruchang_price'=>$ruchang_price,
- 'ruchang_status'=>1,
- 'yajin_number'=>$yajin_number,
- 'yajin_code'=>'/'.$yajin_code,
- 'yajin_price'=>$yajin_price,
- 'yajin_status'=>1,
- 'type'=>$v['type'],
- 'time_id'=>$v['id'],
- 'method_id'=>$data['method_id'],
- ];
- if($data['wucan_money']>0){
- $code_data[ 'wucan_number']=$wucan_number;
- $code_data[ 'wucan_code']='/'.$wucan_code;
- $code_data['wucan_price'] = $wucan_price;
- $code_data[ 'wucan_status']=1;
- }
- $order_code =new Ordercode();
- $order_code->insert($code_data);
- }
- $item_data[] =[
- 'order_id'=>$order_id,
- 'time_id'=>$v['id'],
- 'title'=>$v['title'],
- 'number'=>$v['number'],
- 'price'=>$v['price'],
- 'order_money'=>$v['price']*$v['number'],
- 'type'=>$v['type']
- ];
- if($v['type']==1){
- $end=explode('-',$v['title']);
- $order_model->isUpdate('true',['id'=>$order_id])->save(['end'=>$end[1],'sta'=>$end[0]]);
- }
- }
- $list_code = $order_code->where('order_id',$order_id)->select();
- foreach ($list_code as $kk=>$vv){
- $order_code->isUpdate(true,['id'=>$list_code[$kk]['id']])->save(['name'=>$data['user'][$kk]['name'],'phone'=>$data['user'][$kk]['phone']]);
- if($method_info['type']==2&&$method_info['moshi']!=1){
- $dis_model = new \app\admin\model\Distribution();
- $dis_model->insert(['method_id'=>$data['method_id'],'title'=>$v['title'],'phone'=>$data['user'][$kk]['phone'],'type'=>1]);
- }
- }
- $order_item_model = new Orderitem();
- $order_item_model->insertAll($item_data);
- //生成对应数量二维码
- Db::commit();
- $this->success('订单下单成功',$order_id);
- }catch (\ErrorException $e){
- Db::rollback();
- $this->error('订单失败');
- }
- }
- public function order_list(){
- $order_model = new Order();
- $status=input('status',0);
- //订单状态:1=待支付,2=待核销,3=进行中,4=待评价,5=已完成,6=退款中,7=已退款,8=已取消
- switch ($status){
- case 0:
- $array = [0,1,2,3,4,5,6,7,8];
- break;
- case 1:
- $array = [1];
- break;
- case 2:
- $array = [2];
- break;
- case 3:
- $array = [3];
- break;
- case 4:
- $array = [4];
- break;
- case 5:
- $array = [6,7];
- break;
- case 6:
- $array = [8];
- break;
- }
- $list= $order_model->where('user_id',$this->auth->id)->whereIn('status',$array)->order('id','desc')->paginate();
- foreach ($list as &$v){
- if($v['status']==1){
- $vtime=$v['create_time']+15*60-time();
- if($vtime<0){
- $order_model->isUpdate('true',['id'=>$v['id']])->save(['status'=>8]);
- }
- $v['time'] =$vtime;
- }
- }
- $this->success('我的订单列表',$list);
- }
- public function order_details(){
- $order_id= input('order_id');
- $order_model = new Order();
- $order_item =new Orderitem();
- $order_code = new Ordercode();
- $dis_model = new \app\admin\model\Distribution();
- $order_info= $order_model->where('o.id',$order_id)->alias('o')->join('method m','o.method_id=m.id')->field('o.*,m.huodong_time')->find();
- if(empty($order_info)){
- $this->error('订单信息有误');
- }
- if($order_info['status']){
- $order_info['time']=$order_info['create_time']+30*60-time();
- }
- $order_info['item'] = $order_item->where('order_id',$order_id)->select();
- $order_info['code'] = $order_code->where('order_id',$order_id)->select();
- foreach ($order_info['code'] as $k =>$v){
- $zuowei = $dis_model->where('method_id',$order_info['code'][$k]['method_id'])->where('phone',$order_info['code'][$k]['phone'])->value('number');
- $v['zuowei']=$zuowei;
- }
- $this->success('订单详情',$order_info);
- }
- public function order_pingjia(){
- $data = input();
- $order_model = new Order();
- $yutang_model = new \app\admin\model\Yutang();
- $order_info = $order_model->where('id',$data['order_id'])->find();
- if($order_info['status']==4){
- $pingjia_data=[
- 'yutang_id'=>$order_info['yutang_id'],
- 'user_id'=>$this->auth->id,
- 'score'=>$data['score'],
- 'content'=>$data['content'],
- 'images'=>$data['images'],
- 'create_time'=>time()
- ];
- $pingjia_model = new Pingjia();
- $pingjia_model->insert($pingjia_data);
- $sum_pingja = $pingjia_model->where('yutang_id',$order_info['yutang_id'])->sum('score');
- $count_pingjia = $pingjia_model->where('yutang_id',$order_info['yutang_id'])->count('id');
- $pingjia = floor($sum_pingja/$count_pingjia);
- $yutang_model->isUpdate('true',['id'=>$order_info['yutang_id']])->save(['pingjie'=>$pingjia]);
- $this->success('感谢你的评价');
- }
- else{
- $this->error('订单状态不是待评价');
- }
- }
- public function pingjia_list(){
- $yutang_id= input('yutang_id');
- $pingjia_model = new Pingjia();
- $pingjia= $pingjia_model->alias('p')->join('user u','u.id=p.user_id')->where('p.yutang_id',$yutang_id)->order('p.id','desc')->field('p.*,u.nickname,u.avatar')->paginate();
- $this->success('查看更多评价',$pingjia);
- }
- public function cancel_order(){
- $order_id= input('order_id');
- $order_model = new Order();
- $up = $order_model->isUpdate('true',['user_id'=>$this->auth->id,'id'=>$order_id,'status'=>1])->save(['status'=>8]);
- if($up){
- $this->success('订单已取消');
- }
- else{
- $this->error('订单信息审核不正确');
- }
- }
- public function reason_order(){
- $data = input();
- $order_model = new Order();
- $order_info = $order_model->where('id',$data['order_id'])->where('status',2)->find();
- if(empty($order_info)){
- $this->error('您的订单不支持退款了!');
- }
- $order_data = [
- 'reson_name'=>$data['reson_name'],
- 'reson_desc'=>$data['reson_desc'],
- 'reson_images'=>$data['reson_images'],
- 'reson_money'=>$order_info['order_money'],
- 'reson_time'=>date('Y-m-d H:i:s'),
- 'status'=>7,
- ];
- // 退款功能
- if($order_info['pay_type']=='微信支付') {
- $config = Service::getConfig('wechat');
- $app = Pay::wechat($config);
- $refund_data=[
- 'out_trade_no' => $order_info['order_no'],
- 'out_refund_no' => time(),
- 'total_fee' => $order_info['order_money']*100,
- 'refund_fee' => $order_info['order_money']*100,
- 'refund_desc' => '订单退款',
- 'type'=>'app'
- ];
- $result = $app->refund($refund_data);
- if ($result['return_code'] == 'FAIL' || $result['result_code'] == 'FAIL') {
- $order_model->save(['status' => 2], ['id' => $data['order_id'], 'user_id' => $this->auth->id]);
- $this->error('退款出错请联系商家');
- }
- }
- elseif ($order_info['pay_type']=='支付宝支付'){
- $config = Service::getConfig('alipay');
- $aipay = Pay::alipay($config);
- $refund_data=[
- 'out_trade_no' => $order_info['order_no'],
- 'refund_amount' => $order_info['order_money'],
- ];
- $ai_refund = $aipay->refund($refund_data);
- if ($ai_refund['return_code'] == 'FAIL' || $ai_refund['result_code'] == 'FAIL') {
- $order_model->save(['status' => 2], ['id' => $data['order_id'], 'user_id' => $this->auth->id]);
- $this->error('退款出错请联系商家');
- }
- }
- else{
- $user_money_log_model = new UserMoneyLog();
- $user=$this->auth->getUser();
- $money_log = [
- 'user_id' => $this->auth->id,
- 'type' => 2,
- 'memo' => '订单退款',
- 'money' => $order_info['order_money'],
- 'before' => $user->money,
- 'after' => $user->money + $order_info['order_money'],
- 'createtime' => time(),
- ];
- $user->money +=$order_info['order_money'];
- $user->save();
- $user_money_log_model->insert($money_log);
- }
- $order_model->isUpdate('true',['id'=>$data['order_id']])->save($order_data);
- $sms_model = new Sms();
- $sms_model->order_reund($order_info['phone'],$order_info['order_no'],$order_info['order_money']);
- $this->success('退款成功,稍后到账');
- }
- public function code($code,$image){
- vendor('phpqrcode.phpqrcode');//包含类库文件
- $a= new \QRcode();//实例化类
- $errorCorrectionLevel = 'L';//容错级别
- $matrixPointSize = 6;//生成图片大小
- //生成二维码图片
- $a->png($code,$image, $errorCorrectionLevel, $matrixPointSize, 2);//生成二
- }
- public function user_car(){
- $user_car_model = new Usercar();
- $data = input();
- $usercar_data=[
- 'user_id'=>$this->auth->id,
- 'name'=>$data['name'],
- 'phone'=>$data['phone'],
- ];
- $user_car_model->insert($usercar_data);
- $this->success('添加钓客信息成功');
- }
- public function user_car_del(){
- $user_car_model = new Usercar();
- $car_id = input('car_id');
- $user_car_model->where('id',$car_id)->delete();
- $this->success('钓客信息已删除');
- }
- public function user_car_list(){
- $user_car_model = new Usercar();
- $list = $user_car_model->where('user_id',$this->auth->id)->order('id','ASC')->select();
- $this->success('钓客信息',$list);
- }
- public function huiyu(){
- $sms_model = new Sms();
- $user_model = new \app\admin\model\User();
- $order_model = new Order();
- $order_id = input('order_id');
- $order_info = $order_model->where('id',$order_id)->field('order_no,t_user_id')->find();
- $user_info= $user_model->where('id',$order_info['t_user_id'])->field('sms_number,mobile,duanxin')->find();
- $user = $this->auth->getUser();
- if ($user_info['sms_number'] > 0 && $user_info['duanxin'] == 1) {
- $sms_model->order_huiyu($user_info['mobile'], $order_info['order_no'], $user->nickname);
- }
- $message_data =[
- 'category_id' => 2,
- 'user_id' => $order_info['t_user_id'],
- 'title' => '订单消息',
- 'order_id' => $order_id,
- 'name' => '',
- 'description' => '塘主您好,订单号'.$order_info['order_no'].'用户'.$user->nickname.'发起回鱼申请,请及时处理。',
- 'is_read' => 1,
- 'createtime' => time(),
- ];
- $message_model = new \app\admin\model\Message();
- $message_model->insert($message_data);
- $this->success('已通知鱼塘主');
- }
- public function sms_order(){
- $sms_model = new Smsorder();
- $data= input();
- $add_data = [
- 'user_id' => $this->auth->id,
- 'order_no'=>'SMS'.time().$this->auth->id,
- 'username'=>$this->auth->nickname,
- 'phone' => $this->auth->mobile,
- 'number'=>$data['number'],
- 'pay_money'=>$data['pay_money'],
- 'pay_type'=>$data['pay_type'],
- 'status'=>2,
- 'create_time'=>time(),
- ];
- $order_id = $sms_model->insertGetId($add_data);
- $this->success('下单成功',$order_id);
- }
- public function money_order(){
- $sms_model = new Tzmoneyrecharge();
- $data= input();
- $add_data = [
- 'user_id' => $this->auth->id,
- 'order_no'=>'Bl'.time().$this->auth->id,
- 'money'=>$data['money'],
- 'pay_type'=>$data['pay_type'],
- 'status'=>1,
- 'create_time'=>time(),
- ];
- $order_id = $sms_model->insertGetId($add_data);
- $this->success('下单成功',$order_id);
- }
- }
|