diff --git a/application/api/controller/Order.php b/application/api/controller/Order.php index 8e17ed59..bdf1155b 100644 --- a/application/api/controller/Order.php +++ b/application/api/controller/Order.php @@ -16,14 +16,15 @@ use EasyWeChat\Factory; */ class Order extends ApiBase { - public $like_not_need_login = ['wxmassin', 'lists', 'appInit', 'downLine', 'share', 'config','pcLists','getpege','ttorder']; - + public $like_not_need_login = ['wxmassin', 'lists', 'appInit', 'downLine', 'share', 'config', 'pcLists', 'getpege', 'ttorder']; + //抖音订单回调 - public function ttorder(){ + public function ttorder() + { $ttPay = new ttPay(); $res = $ttPay->run('notify'); } - + //订单列表 public function lists() { @@ -31,27 +32,27 @@ class Order extends ApiBase $order_list = OrderLogic::getOrderList($this->user_id, $type, $this->page_no, $this->page_size); $this->_success('获取成功', $order_list); } - + public function stafflist() { $type = $this->request->get('type', 'all'); $order_list = OrderLogic::stafflist($this->user_id, $type, $this->page_no, $this->page_size); $this->_success('获取成功', $order_list); } - + //员工订单详情页面 public function numberlist() { $type = $this->request->get('type', 'all'); - $tiem= $this->request->get(); - if(isset($tiem['id'])){ - - - $order_list = OrderLogic::timelist($this->user_id, $type,$tiem,$this->page_no, $this->page_size); - $this->_success('获取成功', $order_list); - }else{ - $order_list = OrderLogic::numberlist($this->user_id, $type, $this->page_no, $this->page_size); - $this->_success('获取成功', $order_list); + $tiem = $this->request->get(); + if (isset($tiem['id'])) { + + + $order_list = OrderLogic::timelist($this->user_id, $type, $tiem, $this->page_no, $this->page_size); + $this->_success('获取成功', $order_list); + } else { + $order_list = OrderLogic::numberlist($this->user_id, $type, $this->page_no, $this->page_size); + $this->_success('获取成功', $order_list); } } @@ -61,12 +62,12 @@ class Order extends ApiBase public function buy() { $post = $this->request->post(); - + $post['user_id'] = $this->user_id; $post['client'] = $this->client; - + // $openid = 'oehgp4zzyK34d3TgnXD1ytpeNRjI'; - + // //发送下单成功通知 // $template = [ // 'touser'=>$openid, @@ -79,19 +80,17 @@ class Order extends ApiBase // ] // ]; // $r = send_mini_template($template); - + $check = $this->validate($post, 'app\api\validate\Order.buy'); if (true !== $check) { $this->_error($check); } $action = $post['action']; - - + $info = OrderLogic::info($post, $this->user_id); - - - + + if ($info['code'] == 0) { $this->_error($info['msg']); } @@ -103,11 +102,11 @@ class Order extends ApiBase if ($this->client != Client_::pc && empty($post['pay_way'])) { $this->_error('请联系管理员配置支付方式'); } - - + + $order = OrderLogic::add($this->user_id, $info['data'], $post); - - + + return $order; } @@ -116,7 +115,7 @@ class Order extends ApiBase public function detail() { $order_id = $this->request->get('id'); - if (!$order_id){ + if (!$order_id) { $this->_error('请选择订单'); } $order_detail = OrderLogic::getOrderDetail($order_id, $this->user_id); @@ -172,678 +171,818 @@ class Order extends ApiBase } $this->_error($tips); } - - public function Get_Chinese_WeekDay($Join_Date) + + public function Get_Chinese_WeekDay($Join_Date) { - $WeekDay = date('w', strtotime($Join_Date)); + $WeekDay = date('w', strtotime($Join_Date)); $WeekList = array('日', '一', '二', '三', '四', '五', '六'); return '星期' . $WeekList[$WeekDay]; } - public function get3day(){ + public function get3day() + { $goods_id = $this->request->post('id'); - $order=Db::name('order')->where('id',$goods_id)->find(); //获取到订单的信息 - $goods=Db::name('goods')->where('id',$order['goods_id'])->find(); //获取到商品的信息 - - + $order = Db::name('order')->where('id', $goods_id)->find(); //获取到订单的信息 + $goods = Db::name('goods')->where('id', $order['goods_id'])->find(); //获取到商品的信息 + + // $staff=Db::name('staff')->where('goods_id',$goods['brand_id'])->select(); //查询到所有的保洁师傅 // dump($staff);die; - + $days = []; $current = date('Y-m-d'); - for($i = 1 ; $i <= 3 ;$i++){ + for ($i = 1; $i <= 3; $i++) { $current = date("Y-m-d", strtotime($current . "+1 day")); - $days[] = $current; + $days[] = $current; } - - $data = []; - foreach ($days as $k=>$v){ - $start = strtotime($v); //开始时间 - $end = strtotime($v.' 23:59:59'); //结束时间 - - //统计这个时间请假的用户的数据 - $orders=Db::name('order_exe')->where('addtime',1)->where('autotime','>=',$start)->where('autotime','<=',$end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅 - $oneDimensionalArray = array_column($orders, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分 - - - $lent=Db::name('leave')->where('addtime',1)->where('time','>=',$start)->where('time','<=',$end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select(); - $lentuser = array_column($lent,'user_id'); - - //判断上午 - $numbersw=Db::name('staff') - ->where('onwork',1) - ->where('goods_id',$goods['brand_id']) - ->whereNotIn('id',$oneDimensionalArray) // $array为要比较的数组 - ->whereNotIn('id',$lentuser) // $array为要比较的数组 - ->count(); //获取到请假的人数 - $order_numbersw=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',0)->where('addtime',1)->count();// 没有派单的保洁师 - - $numbersw=$numbersw-$order_numbersw; - - + $data = []; + foreach ($days as $k => $v) { + $start = strtotime($v); //开始时间 + $end = strtotime($v . ' 23:59:59'); //结束时间 + //统计这个时间请假的用户的数据 - $ordersxw=Db::name('order_exe')->where('addtime',2)->where('autotime','>=',$start)->where('autotime','<=',$end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅 - $oneDimensionalArrayxw= array_column($ordersxw, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分 - - - $lentxw=Db::name('leave')->where('addtime',2)->where('time','>=',$start)->where('time','<=',$end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select(); - $lentuserxw = array_column($lentxw,'user_id'); - - - - //判断下午 - $numberxw=Db::name('staff') - ->where('onwork',1) - ->whereNotIn('id',$oneDimensionalArrayxw) // $array为要比较的数组 - ->where('goods_id',$goods['brand_id']) - ->whereNotIn('id',$lentuserxw) // $array为要比较的数组 - ->count(); //获取到请假的人数 - $order_numberxw=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',0)->where('addtime',2)->count();// 没有派单的保洁师 - $numberxw=$numberxw-$order_numberxw; - if($numbersw>0){ - $coied=false; - } else{ - $coied=true; - } - if($numberxw>0){ - $coiedxw=false; - } else{ - $coiedxw=true; - } - - $data[] = [ - 'date'=>$v, - 'week'=>$this->Get_Chinese_WeekDay($v), - 'hourLists'=>[ - ['hour'=>"上午",'select'=>false,'disabled'=>$coied,'selectDay'=>$v,'staffnumber'=>$numbersw], - ['hour'=>'下午','select'=>false,'disabled'=>$coiedxw,'selectDay'=>$v,'staffnumber'=>$numberxw], - ] - ]; - } - $data[0]['select'] = true; - $this->_success('获取成功', $data); - - } - - public function getday(){ - $post = $this->request->post(); - - $order=Db::name('order')->where('id',$post['data']['id'])->find(); //获取到订单的信息 - $goods=Db::name('goods')->where('id',$order['goods_id'])->find(); //获取到商品的信息 - $day = $post['data']['day']; - $start = strtotime($day); - $end = strtotime($day.' 23:59:59'); - - - - //统计这个时间请假的用户的数据 - $orders=Db::name('order_exe')->where('addtime',1)->where('autotime','>=',$start)->where('autotime','<=',$end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅 + $orders = Db::name('order_exe')->where('addtime', 1)->where('autotime', '>=', $start)->where('autotime', '<=', $end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅 $oneDimensionalArray = array_column($orders, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分 - - - $lent=Db::name('leave')->where('addtime',1)->where('time','>=',$start)->where('time','<=',$end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select(); - $lentuser = array_column($lent,'user_id'); - $numbersw=Db::name('staff') - ->where('onwork',1) - ->where('goods_id',$goods['brand_id']) - ->whereNotIn('id',$oneDimensionalArray) // $array为要比较的数组 - ->whereNotIn('id',$lentuser) // $array为要比较的数组 - ->count(); - - $order_numbersw=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',0)->where('addtime',1)->count();// 没有派单的保洁师 - - $numbersw=$numbersw-$order_numbersw; - + + + $lent = Db::name('leave')->where('addtime', 1)->where('time', '>=', $start)->where('time', '<=', $end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select(); + $lentuser = array_column($lent, 'user_id'); + + + //判断上午 + $numbersw = Db::name('staff') + ->where('onwork', 1) + ->where('goods_id', $goods['brand_id']) + ->whereNotIn('id', $oneDimensionalArray) // $array为要比较的数组 + ->whereNotIn('id', $lentuser) // $array为要比较的数组 + ->count(); //获取到请假的人数 + $order_numbersw = Db::name('order_exe')->where('autotime', '>=', $start)->where('autotime', '<=', $end)->where('staff_id', 0)->where('addtime', 1)->count();// 没有派单的保洁师 + + $numbersw = $numbersw - $order_numbersw; + + //统计这个时间请假的用户的数据 - $ordersxw=Db::name('order_exe')->where('addtime',2)->where('autotime','>=',$start)->where('autotime','<=',$end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅 - $oneDimensionalArrayxw= array_column($ordersxw, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分 - - - $lentxw=Db::name('leave')->where('addtime',2)->where('time','>=',$start)->where('time','<=',$end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select(); - $lentuserxw = array_column($lentxw,'user_id'); - - - - - - //判断下午 - $numberxw=Db::name('staff') - ->where('onwork',1) - ->whereNotIn('id',$oneDimensionalArrayxw) // $array为要比较的数组 - ->whereNotIn('id',$lentuserxw) // $array为要比较的数组 - ->where('goods_id',$goods['brand_id']) - ->count(); //获取到请假的人数 - - $order_numberxw=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id',0)->where('addtime',2)->count();// 没有派单的保洁师 - $numberxw=$numberxw-$order_numberxw; - - if($numbersw>0){ - $coied=false; - }else{ - $coied=true; - } - if($numberxw>0){ - $coiedxw=false; - }else{ - $coiedxw=true; - } - - $data[] = [ - 'date'=>$day, - 'week'=>$this->Get_Chinese_WeekDay($day), - 'hourLists'=>[ - ['hour'=>'上午','select'=>false,'disabled'=>$coied,'selectDay'=>$day,'staffnumber'=>$numbersw], - ['hour'=>'下午','select'=>false,'disabled'=>$coiedxw,'selectDay'=>$day,'staffnumber'=>$numberxw], + $ordersxw = Db::name('order_exe')->where('addtime', 2)->where('autotime', '>=', $start)->where('autotime', '<=', $end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅 + $oneDimensionalArrayxw = array_column($ordersxw, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分 + + + $lentxw = Db::name('leave')->where('addtime', 2)->where('time', '>=', $start)->where('time', '<=', $end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select(); + $lentuserxw = array_column($lentxw, 'user_id'); + + + //判断下午 + $numberxw = Db::name('staff') + ->where('onwork', 1) + ->whereNotIn('id', $oneDimensionalArrayxw) // $array为要比较的数组 + ->where('goods_id', $goods['brand_id']) + ->whereNotIn('id', $lentuserxw) // $array为要比较的数组 + ->count(); //获取到请假的人数 + $order_numberxw = Db::name('order_exe')->where('autotime', '>=', $start)->where('autotime', '<=', $end)->where('staff_id', 0)->where('addtime', 2)->count();// 没有派单的保洁师 + $numberxw = $numberxw - $order_numberxw; + if ($numbersw > 0) { + $coied = false; + } else { + $coied = true; + } + if ($numberxw > 0) { + $coiedxw = false; + } else { + $coiedxw = true; + } + + $data[] = [ + 'date' => $v, + 'week' => $this->Get_Chinese_WeekDay($v), + 'hourLists' => [ + ['hour' => "上午", 'select' => false, 'disabled' => $coied, 'selectDay' => $v, 'staffnumber' => $numbersw], + ['hour' => '下午', 'select' => false, 'disabled' => $coiedxw, 'selectDay' => $v, 'staffnumber' => $numberxw], ] ]; - $data[0]['select'] = true; - $this->_success('获取成功', $data); + } + $data[0]['select'] = true; + $this->_success('获取成功', $data); + } - - public function sendgzhmsg($orderid = ''){ - $uid = $this->user_id; - // $uid = 366; - $openids=Db::name('user_auth')->where('user_id',$uid)->find(); //获取用户的ID - $adder=Db::name('user_address')->where('user_id',$uid)->find(); - // $openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; - $openid = $openids['openid']; - $data = [ - 'touser'=>$openid, - 'url'=>'', - 'template_id'=>'MJBxsfAT18v9fQ8LYK2v1AF4iRkprNp1KPVm1ses64I', //模板id - 'data'=>[ - 'time4'=>[ - 'value'=>date('Y-m-d H:i',time()) + + public function getday() + { + $post = $this->request->post(); + + $order = Db::name('order')->where('id', $post['data']['id'])->find(); //获取到订单的信息 + $goods = Db::name('goods')->where('id', $order['goods_id'])->find(); //获取到商品的信息 + $day = $post['data']['day']; + $start = strtotime($day); + $end = strtotime($day . ' 23:59:59'); + + + //统计这个时间请假的用户的数据 + $orders = Db::name('order_exe')->where('addtime', 1)->where('autotime', '>=', $start)->where('autotime', '<=', $end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅 + $oneDimensionalArray = array_column($orders, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分 + + + $lent = Db::name('leave')->where('addtime', 1)->where('time', '>=', $start)->where('time', '<=', $end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select(); + $lentuser = array_column($lent, 'user_id'); + $numbersw = Db::name('staff') + ->where('onwork', 1) + ->where('goods_id', $goods['brand_id']) + ->whereNotIn('id', $oneDimensionalArray) // $array为要比较的数组 + ->whereNotIn('id', $lentuser) // $array为要比较的数组 + ->count(); + + $order_numbersw = Db::name('order_exe')->where('autotime', '>=', $start)->where('autotime', '<=', $end)->where('staff_id', 0)->where('addtime', 1)->count();// 没有派单的保洁师 + + $numbersw = $numbersw - $order_numbersw; + + //统计这个时间请假的用户的数据 + $ordersxw = Db::name('order_exe')->where('addtime', 2)->where('autotime', '>=', $start)->where('autotime', '<=', $end)->whereNotNull('staff_id')->field('staff_id')->group('staff_id')->select(); //查询有订单的保洁师傅 + $oneDimensionalArrayxw = array_column($ordersxw, 'staff_id'); // 根据自己的表格字段名修改'字段名'部分 + + + $lentxw = Db::name('leave')->where('addtime', 2)->where('time', '>=', $start)->where('time', '<=', $end)->whereNotNull('user_id')->field('user_id')->group('user_id')->select(); + $lentuserxw = array_column($lentxw, 'user_id'); + + + //判断下午 + $numberxw = Db::name('staff') + ->where('onwork', 1) + ->whereNotIn('id', $oneDimensionalArrayxw) // $array为要比较的数组 + ->whereNotIn('id', $lentuserxw) // $array为要比较的数组 + ->where('goods_id', $goods['brand_id']) + ->count(); //获取到请假的人数 + + $order_numberxw = Db::name('order_exe')->where('autotime', '>=', $start)->where('autotime', '<=', $end)->where('staff_id', 0)->where('addtime', 2)->count();// 没有派单的保洁师 + $numberxw = $numberxw - $order_numberxw; + + if ($numbersw > 0) { + $coied = false; + } else { + $coied = true; + } + if ($numberxw > 0) { + $coiedxw = false; + } else { + $coiedxw = true; + } + + $data[] = [ + 'date' => $day, + 'week' => $this->Get_Chinese_WeekDay($day), + 'hourLists' => [ + ['hour' => '上午', 'select' => false, 'disabled' => $coied, 'selectDay' => $day, 'staffnumber' => $numbersw], + ['hour' => '下午', 'select' => false, 'disabled' => $coiedxw, 'selectDay' => $day, 'staffnumber' => $numberxw], + ] + ]; + $data[0]['select'] = true; + $this->_success('获取成功', $data); + } + + public function sendgzhmsg($orderid = '') + { + $uid = $this->user_id; + // $uid = 366; + $openids = Db::name('user_auth')->where('user_id', $uid)->find(); //获取用户的ID + $adder = Db::name('user_address')->where('user_id', $uid)->find(); + // $openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; + $openid = $openids['openid'] ?? null; + if (!$openid) { + return false; // 未绑定公众号 + } + $data = [ + 'touser' => $openid, + 'url' => '', + 'template_id' => 'MJBxsfAT18v9fQ8LYK2v1AF4iRkprNp1KPVm1ses64I', //模板id + 'data' => [ + 'time4' => [ + 'value' => date('Y-m-d H:i', time()) ], - 'thing1'=>[ - 'value'=>$adder['contact'] + 'thing1' => [ + 'value' => $adder['contact'] ] ] ]; - $config = WeChatServer::getOaConfig(); - $app = Factory::officialAccount($config); - - $r = $app->template_message->send($data); - - return true; + $config = WeChatServer::getOaConfig(); + $app = Factory::officialAccount($config); + + $r = $app->template_message->send($data); + + return true; } - - public function shensatff($id){ + + public function shensatff($id) + { dump($id); - - } - - public function putday(){ - $post = $this->request->post(); - $sw = $post['data']['hourLists'][0]['select']; - $xw = $post['data']['hourLists'][1]['select']; - $orderid=$post['data']['id']; //传递进来的订单id - $day = $post['data']['date']; - $order=Db::name('order')->where('id',$orderid)->find(); //获取到订单的基本信息 - $goods=Db::name('goods')->where('id',$order['goods_id'])->find(); - if($order['code']<=0){ - $this->_error('订单次数已不足无法预约'); - } - - if($sw && $xw){ - $code=Db::name('order')->where('id',$orderid)->find(); - if($code['code']<=2){ - return 20; - }else{ - $data=[ - 'order_sn'=>$order['order_sn'], //订单编号 - 'create_time'=>time(), - // 'fworder_sn'=> $post['fworder_sn'], - 'date'=>$day, - 'xq'=>$this->Get_Chinese_WeekDay($day), - 'type'=>3, - 'status'=>0, - 'addtime'=>1, - 'autotime'=>strtotime($day), - ]; - $list=Db::name('order_exe')->data($data)->insert(); - $datas=[ - 'order_sn'=>$order['order_sn'], //订单编号 - 'create_time'=>time(), - // 'fworder_sn'=> $post['fworder_sn'], - 'date'=>$day, - 'xq'=>$this->Get_Chinese_WeekDay($day), - 'type'=>3, - 'status'=>0, - 'addtime'=>2, - 'autotime'=>strtotime($day), - ]; - $list=Db::name('order_exe')->data($datas)->insert(); - $order=Db::name('order')->where('id',$orderid)->update(['code'=>$order['code']-2]); //获取到订单的基本信息 - $this->sendgzhmsg($day); - if($order['admin_id']!=NULL){ - $admin=Db::name('admin')->where('id',$order['admin_id'])->find(); - $openids=Db::name('user_auth')->where('user_id',$admin['user_id'])->find(); //获取用户的ID - //$time=date('Y-m-d',$orders['autotime']); - //$openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; - $openid = $openids['openid']; - $data = [ - 'touser'=>$openid, - 'url'=>'', - 'template_id'=>'9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', //模板id - 'data'=>[ - 'keyword1'=>[ - 'value'=>$order['order_sn'] - ], - 'keyword2'=>[ - 'value'=>$goods['name'] - ], - 'keyword3'=>[ - 'value'=>$order['consignee'] - ], - 'keyword4'=>[ - 'value'=>$order['mobile'] - ], - 'keyword5'=>[ - 'value'=>$day - ], - - ] - ]; - $config = WeChatServer::getOaConfig(); - $app = Factory::officialAccount($config); - $r = $app->template_message->send($data); - } - $this->_success('预约成功,待上门', $list); - - } - } - if($sw){ - if($order>0){ - $data=[ - 'order_sn'=>$order['order_sn'], //订单编号 - 'create_time'=>time(), - // 'fworder_sn'=> $post['fworder_sn'], - 'date'=>$day, - 'xq'=>$this->Get_Chinese_WeekDay($day), - 'type'=>3, - 'status'=>0, - 'addtime'=>1, - 'autotime'=>strtotime($day), - ]; - $list=Db::name('order_exe')->data($data)->insert(); - $orderss=Db::name('order')->where('id',$orderid)->update(['code'=>$order['code']-1]); //获取到订单的基本信息 - $this->sendgzhmsg($day); - if($order['admin_id']!=NULL){ - $admin=Db::name('admin')->where('id',$order['admin_id'])->find(); - $openids=Db::name('user_auth')->where('user_id',$admin['user_id'])->find(); //获取用户的ID - //$time=date('Y-m-d',$orders['autotime']); - //$openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; - $openid = $openids['openid']; - $data = [ - 'touser'=>$openid, - 'url'=>'', - 'template_id'=>'9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', //模板id - 'data'=>[ - 'keyword1'=>[ - 'value'=>$order['order_sn'] - ], - 'keyword2'=>[ - 'value'=>$goods['name'] - ], - 'keyword3'=>[ - 'value'=>$order['consignee'] - ], - 'keyword4'=>[ - 'value'=>$order['mobile'] - ], - 'keyword5'=>[ - 'value'=>$day.'.8:00-12:00' - ], - - ] - ]; - $config = WeChatServer::getOaConfig(); - $app = Factory::officialAccount($config); - $r = $app->template_message->send($data); - } - - - $this->_success('预约成功,待上门', $list); - }else{ - return 20; - } - } - if($xw){ - if($order>0){ - $data=[ - 'order_sn'=>$order['order_sn'], //订单编号 - 'create_time'=>time(), - // 'fworder_sn'=> $post['fworder_sn'], - 'date'=>$day, - 'xq'=>$this->Get_Chinese_WeekDay($day), - 'type'=>3, - 'status'=>0, - 'addtime'=>2, - 'autotime'=>strtotime($day), - ]; - $list=Db::name('order_exe')->data($data)->insert(); - $order=Db::name('order')->where('id',$orderid)->update(['code'=>$order['code']-1]); //获取到订单的基本信息 - $this->sendgzhmsg($day); - if($order['admin_id']!=NULL){ - $admin=Db::name('admin')->where('id',$order['admin_id'])->find(); - $openids=Db::name('user_auth')->where('user_id',$admin['user_id'])->find(); //获取用户的ID - //$time=date('Y-m-d',$orders['autotime']); - //$openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; - $openid = $openids['openid']; - $data = [ - 'touser'=>$openid, - 'url'=>'', - 'template_id'=>'9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', //模板id - 'data'=>[ - 'keyword1'=>[ - 'value'=>$order['order_sn'] - ], - 'keyword2'=>[ - 'value'=>$goods['name'] - ], - 'keyword3'=>[ - 'value'=>$order['consignee'] - ], - 'keyword4'=>[ - 'value'=>$order['mobile'] - ], - 'keyword5'=>[ - 'value'=>$day.'.14:00-16:00' - ], - - ] - ]; - $config = WeChatServer::getOaConfig(); - $app = Factory::officialAccount($config); - $r = $app->template_message->send($data); - } - - $this->_success('预约成功,待上门', $list); - }else{ - return 20; - } - } - } - - //保洁师开始接单 - public function take(){ - $order_id = $this->request->post('params'); - $order=Db::name('order_exe')->where('id',$order_id)->find(); - if($order['autotime']-time()>24*3600){ - $this->_error('无法接单,未到时间'); - }else{ - $toke=Db::name('order_exe')->where('id', $order_id )->update(['status'=>1]); - $this->_success('接单成功'); - } - } - - //保洁师开始接单 - public function wego(){ - $order_id = $this->request->post('params'); - $toke=Db::name('order_exe')->where('id', $order_id )->update(['status'=>1,'timeadd'=>time(),'staff_status'=>1]); - $this->_success('接单成功'); - } - - //保洁师结束服务 - public function ends(){ - $order_id = $this->request->post('params'); - $toke=Db::name('order_exe')->where('id', $order_id )->update(['status'=>2,'timeout'=>time(),'staff_status'=>1]); - $this->_success('接单成功'); - } - - //订单的详情显示 - - public function orderinfo(){ - $type = $this->request->post('type', 'all'); - $post=$this->request->post(); - $order_sn=$post['id']['order_sn']; - $order_list = OrderLogic::orderinfo($this->user_id, $type,$order_sn,$this->page_no, $this->page_size); - $this->_success('获取成功', $order_list); - } - - //微信的通知 - public function wxmassin(){ - - $start = strtotime(date("Y-m-d",strtotime("+1 day"))); - $end =$start+24*3600-1; - $order=Db::name('order_exe')->where('autotime','>=',$start)->where('autotime','<=',$end)->where('staff_id','<>',0)->select(); - foreach ($order as &$orders) { - $custom=Db::name('order')->where('order_sn',$orders['order_sn'])->find(); - $goods=Db::name('goods')->where('id',$custom['goods_id'])->find(); - $user=Db::name('staff')->where('id',$orders['staff_id'])->find(); - - if($orders['addtime']=1){ - $timesw='上午'; - }else{ - $timesw='下午'; - } - - // $uid = 366; - $openids=Db::name('user_auth')->where('user_id',$user['user_id'])->find(); //获取用户的ID - $time=date('Y-m-d',$orders['autotime']); - // $openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; - $openid = $openids['openid']; - $data = [ - 'touser'=>$openid, - 'url'=>'', - 'template_id'=>'YYsFPwTCrPcxi0JA_zg0xnz6uFaVAlobfTGvhQVDglE', //模板id - 'data'=>[ - 'keyword1'=>[ - 'value'=>$goods['name'] - ], - 'keyword2'=>[ - 'value'=> $time.$timesw - ], - 'keyword3'=>[ - 'value'=>$custom['address'] - ], - 'keyword4'=>[ - 'value'=>$custom['consignee'] - ], - 'keyword5'=>[ - 'value'=>$custom['mobile'] - ], - + +// public function putday() +// { +// $post = $this->request->post(); +// $sw = $post['data']['hourLists'][0]['select']; +// $xw = $post['data']['hourLists'][1]['select']; +// $orderid = $post['data']['id']; //传递进来的订单id +// $day = $post['data']['date']; +// $order = Db::name('order')->where('id', $orderid)->find(); //获取到订单的基本信息 +// $goods = Db::name('goods')->where('id', $order['goods_id'])->find(); +// if ($order['code'] <= 0) { +// $this->_error('订单次数已不足无法预约'); +// } +// +// if ($sw && $xw) { +// $code = Db::name('order')->where('id', $orderid)->find(); +// if ($code['code'] <= 2) { +// return 20; +// } else { +// $data = [ +// 'order_sn' => $order['order_sn'], //订单编号 +// 'create_time' => time(), +// // 'fworder_sn'=> $post['fworder_sn'], +// 'date' => $day, +// 'xq' => $this->Get_Chinese_WeekDay($day), +// 'type' => 3, +// 'status' => 0, +// 'addtime' => 1, +// 'autotime' => strtotime($day), +// ]; +// $list = Db::name('order_exe')->data($data)->insert(); +// $datas = [ +// 'order_sn' => $order['order_sn'], //订单编号 +// 'create_time' => time(), +// // 'fworder_sn'=> $post['fworder_sn'], +// 'date' => $day, +// 'xq' => $this->Get_Chinese_WeekDay($day), +// 'type' => 3, +// 'status' => 0, +// 'addtime' => 2, +// 'autotime' => strtotime($day), +// ]; +// $list = Db::name('order_exe')->data($datas)->insert(); +// $order = Db::name('order')->where('id', $orderid)->update(['code' => $order['code'] - 2]); //获取到订单的基本信息 +// $this->sendgzhmsg($day); +// if ($order['admin_id'] != NULL) { +// $admin = Db::name('admin')->where('id', $order['admin_id'])->find(); +// $openids = Db::name('user_auth')->where('user_id', $admin['user_id'])->find(); //获取用户的ID +// //$time=date('Y-m-d',$orders['autotime']); +// //$openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; +// $openid = $openids['openid']; +// if ($openid != null) +// { +// $data = [ +// 'touser' => $openid, +// 'url' => '', +// 'template_id' => '9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', //模板id +// 'data' => [ +// 'keyword1' => [ +// 'value' => $order['order_sn'] +// ], +// 'keyword2' => [ +// 'value' => $goods['name'] +// ], +// 'keyword3' => [ +// 'value' => $order['consignee'] +// ], +// 'keyword4' => [ +// 'value' => $order['mobile'] +// ], +// 'keyword5' => [ +// 'value' => $day +// ], +// +// ] +// ]; +// $config = WeChatServer::getOaConfig(); +// $app = Factory::officialAccount($config); +// $r = $app->template_message->send($data); +// } +// } +// $this->_success('预约成功,待上门', $list); +// +// } +// } +// if ($sw) { +// if ($order > 0) { +// $data = [ +// 'order_sn' => $order['order_sn'], //订单编号 +// 'create_time' => time(), +// // 'fworder_sn'=> $post['fworder_sn'], +// 'date' => $day, +// 'xq' => $this->Get_Chinese_WeekDay($day), +// 'type' => 3, +// 'status' => 0, +// 'addtime' => 1, +// 'autotime' => strtotime($day), +// ]; +// $list = Db::name('order_exe')->data($data)->insert(); +// +// $orderss = Db::name('order')->where('id', $orderid)->update(['code' => $order['code'] - 1]); +// //获取到订单的基本信息 +// $this->sendgzhmsg($day); +// if ($order['admin_id'] != null) { +// $admin = Db::name('admin')->where('id', $order['admin_id'])->find(); +// $openids = Db::name('user_auth')->where('user_id', $admin['user_id'])->find(); //获取用户的ID +// //$time=date('Y-m-d',$orders['autotime']); +// //$openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; +// $openid = $openids['openid']; +// if ($openid != null) +// { +// $data = [ +// 'touser' => $openid, +// 'url' => '', +// 'template_id' => '9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', //模板id +// 'data' => [ +// 'keyword1' => [ +// 'value' => $order['order_sn'] +// ], +// 'keyword2' => [ +// 'value' => $goods['name'] +// ], +// 'keyword3' => [ +// 'value' => $order['consignee'] +// ], +// 'keyword4' => [ +// 'value' => $order['mobile'] +// ], +// 'keyword5' => [ +// 'value' => $day . '.8:00-12:00' +// ], +// +// ] +// ]; +// $config = WeChatServer::getOaConfig(); +// $app = Factory::officialAccount($config); +// $r = $app->template_message->send($data); +// } +// } +// +// +// $this->_success('预约成功,待上门', $list); +// } else { +// return 20; +// } +// +// } +// if ($xw) { +// if ($order > 0) { +// $data = [ +// 'order_sn' => $order['order_sn'], //订单编号 +// 'create_time' => time(), +// // 'fworder_sn'=> $post['fworder_sn'], +// 'date' => $day, +// 'xq' => $this->Get_Chinese_WeekDay($day), +// 'type' => 3, +// 'status' => 0, +// 'addtime' => 2, +// 'autotime' => strtotime($day), +// ]; +// $list = Db::name('order_exe')->data($data)->insert(); +// $order = Db::name('order')->where('id', $orderid)->update(['code' => $order['code'] - 1]); //获取到订单的基本信息 +// $this->sendgzhmsg($day); +// if ($order['admin_id'] != NULL) { +// $admin = Db::name('admin')->where('id', $order['admin_id'])->find(); +// $openids = Db::name('user_auth')->where('user_id', $admin['user_id'])->find(); //获取用户的ID +// //$time=date('Y-m-d',$orders['autotime']); +// //$openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; +// $openid = $openids['openid']; +// if ( $openid != null) +// { +// //发送预约成功消息 +// $data = [ +// 'touser' => $openid, +// 'url' => '', +// 'template_id' => '9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', //模板id +// 'data' => [ +// 'keyword1' => [ +// 'value' => $order['order_sn'] +// ], +// 'keyword2' => [ +// 'value' => $goods['name'] +// ], +// 'keyword3' => [ +// 'value' => $order['consignee'] +// ], +// 'keyword4' => [ +// 'value' => $order['mobile'] +// ], +// 'keyword5' => [ +// 'value' => $day . '.14:00-16:00' +// ], +// +// ] +// ]; +// $config = WeChatServer::getOaConfig(); +// $app = Factory::officialAccount($config); +// $r = $app->template_message->send($data); +// } +// } +// +// $this->_success('预约成功,待上门', $list); +// } else { +// return 20; +// } +// } +// +// } + + public function putday() + { + $post = $this->request->post(); + $hourLists = $post['data']['hourLists'] ?? []; + $orderid = $post['data']['id'] ?? 0; + $day = $post['data']['date'] ?? ''; + if (!$orderid || !$day || count($hourLists) < 2) { + $this->_error('参数错误'); + } + // 时间段选择 + $sw = !empty($hourLists[0]['select']); // 上午 + $xw = !empty($hourLists[1]['select']); // 下午 + if (!$sw && !$xw) { + $this->_error('请选择预约时间段'); + } + // 获取订单 + $order = Db::name('order')->where('id', $orderid)->find(); + if (!$order) { + $this->_error('订单不存在'); + } + // 获取商品 + $goods = Db::name('goods')->where('id', $order['goods_id'])->find(); + // 需要扣的次数 + $needCode = ($sw && $xw) ? 2 : 1; + if ($order['code'] < $needCode) { + $this->_error('订单次数不足,无法预约'); + } + Db::startTrans(); + try { + // 上午 + if ($sw) { + Db::name('order_exe')->insert([ + 'order_sn' => $order['order_sn'], + 'create_time'=> time(), + 'date' => $day, + 'xq' => $this->Get_Chinese_WeekDay($day), + 'type' => 3, + 'status' => 0, + 'addtime' => 1, + 'autotime' => strtotime($day), + 'goods_id' => $goods['id'], + ]); + } + // 下午 + if ($xw) { + Db::name('order_exe')->insert([ + 'order_sn' => $order['order_sn'], + 'create_time'=> time(), + 'date' => $day, + 'xq' => $this->Get_Chinese_WeekDay($day), + 'type' => 3, + 'status' => 0, + 'addtime' => 2, + 'autotime' => strtotime($day), + 'goods_id' => $goods['id'], + ]); + } + // 扣次数 + Db::name('order') + ->where('id', $orderid) + ->update(['code' => $order['code'] - $needCode]); + Db::commit(); + } catch (\Exception $e) { + Db::rollback(); + $this->_error('预约失败,请稍后重试'); + } + // 公众号通知 + $this->sendgzhmsg($day); + // 通知管理员 + if (!empty($order['admin_id'])) { + $admin = Db::name('admin')->where('id', $order['admin_id'])->find(); + if ($admin) { + $openids = Db::name('user_auth')->where('user_id', $admin['user_id'])->find(); + $openid = $openids['openid'] ?? null; + if ($openid) { + $timeStr = $sw && $xw + ? $day + : ($sw ? $day . ' 8:00-12:00' : $day . ' 14:00-16:00'); + + $data = [ + 'touser' => $openid, + 'url' => '', + 'template_id' => '9ESlNoZweXTioNwyaDuSY9fIXCKhnrBi2Gu0Hl8cmAo', + 'data' => [ + 'keyword1' => ['value' => $order['order_sn']], + 'keyword2' => ['value' => $goods['name'] ?? ''], + 'keyword3' => ['value' => $order['consignee']], + 'keyword4' => ['value' => $order['mobile']], + 'keyword5' => ['value' => $timeStr], ] ]; - $config = WeChatServer::getOaConfig(); - $app = Factory::officialAccount($config); - $r = $app->template_message->send($data); - - - } - - - + + $config = WeChatServer::getOaConfig(); + $app = Factory::officialAccount($config); + $app->template_message->send($data); + } + } + } + + $this->_success('预约成功,待上门'); } - - public function getpege(){ - $id = $this->request->get('id'); - $date=Db::name('pageweb')->where('id',$id)->find(); - $this->_success('获取数据成功',$date); - // dump($id); - } - + + + //保洁师开始接单 + public function take() + { + $order_id = $this->request->post('params'); + $order = Db::name('order_exe')->where('id', $order_id)->find(); + if ($order['autotime'] - time() > 24 * 3600) { + $this->_error('无法接单,未到时间'); + } else { + $toke = Db::name('order_exe')->where('id', $order_id)->update(['status' => 1]); + $this->_success('接单成功'); + } + } + + //保洁师开始接单 + public function wego() + { + $order_id = $this->request->post('params'); + $toke = Db::name('order_exe')->where('id', $order_id)->update(['status' => 1, 'timeadd' => time(), 'staff_status' => 1]); + $this->_success('接单成功'); + } + + //保洁师结束服务 + public function ends() + { + $order_id = $this->request->post('params'); + $toke = Db::name('order_exe')->where('id', $order_id)->update(['status' => 2, 'timeout' => time(), 'staff_status' => 1]); + $this->_success('接单成功'); + } + + //订单的详情显示 + + public function orderinfo() + { + $type = $this->request->post('type', 'all'); + $post = $this->request->post(); + $order_sn = $post['id']; + $order_list = OrderLogic::orderinfo($this->user_id, $type, $order_sn, $this->page_no, $this->page_size); + $this->_success('获取成功', $order_list); + } + + //微信的通知 + public function wxmassin() + { + + $start = strtotime(date("Y-m-d", strtotime("+1 day"))); + $end = $start + 24 * 3600 - 1; + $order = Db::name('order_exe')->where('autotime', '>=', $start)->where('autotime', '<=', $end)->where('staff_id', '<>', 0)->select(); + foreach ($order as &$orders) { + $custom = Db::name('order')->where('order_sn', $orders['order_sn'])->find(); + $goods = Db::name('goods')->where('id', $custom['goods_id'])->find(); + $user = Db::name('staff')->where('id', $orders['staff_id'])->find(); + + if ($orders['addtime'] = 1) { + $timesw = '上午'; + } else { + $timesw = '下午'; + } + + // $uid = 366; + $openids = Db::name('user_auth')->where('user_id', $user['user_id'])->find(); //获取用户的ID + $time = date('Y-m-d', $orders['autotime']); + // $openid = 'o_XDv5_Cq72XDOx1qvzq2kcaOYWA'; + $openid = $openids['openid']; + $data = [ + 'touser' => $openid, + 'url' => '', + 'template_id' => 'YYsFPwTCrPcxi0JA_zg0xnz6uFaVAlobfTGvhQVDglE', //模板id + 'data' => [ + 'keyword1' => [ + 'value' => $goods['name'] + ], + 'keyword2' => [ + 'value' => $time . $timesw + ], + 'keyword3' => [ + 'value' => $custom['address'] + ], + 'keyword4' => [ + 'value' => $custom['consignee'] + ], + 'keyword5' => [ + 'value' => $custom['mobile'] + ], + + ] + ]; + $config = WeChatServer::getOaConfig(); + $app = Factory::officialAccount($config); + $r = $app->template_message->send($data); + + + } + + + } + + public function getpege() + { + $id = $this->request->get('id'); + $date = Db::name('pageweb')->where('id', $id)->find(); + $this->_success('获取数据成功', $date); + // dump($id); + } + } -Class ttPay{ - - private $api_url='https://developer.toutiao.com/api/apps/ecpay/v1/'; +class ttPay +{ + + private $api_url = 'https://developer.toutiao.com/api/apps/ecpay/v1/'; private $app_id; private $token; private $salt; - public function __construct() { + public function __construct() + { $this->app_id = 'tt0523739e9a12236501'; - $this->token='123qazqweeesdflomswwe'; - $this->salt='ejAuHvbI472euyhb34aVyLD92ll9tgZCqWnMi0tX'; - } - - public function run($action,$order = null){ - $action=$action?$action:'order'; - if(!in_array($action,['order','query','refund','settle','notify','set'])){ - echo '非法请求';die; - } - return $this->$action($order); + $this->token = '123qazqweeesdflomswwe'; + $this->salt = 'ejAuHvbI472euyhb34aVyLD92ll9tgZCqWnMi0tX'; } - + + public function run($action, $order = null) + { + $action = $action ? $action : 'order'; + if (!in_array($action, ['order', 'query', 'refund', 'settle', 'notify', 'set'])) { + echo '非法请求'; + die; + } + return $this->$action($order); + } + //下单 - private function order($order){ - $data=[ - 'out_order_no'=>$order['order_sn'], - 'total_amount'=>1, - 'subject'=>'购买服务', - 'body'=>'购买商品', - 'valid_time'=>3600, + private function order($order) + { + $data = [ + 'out_order_no' => $order['order_sn'], + 'total_amount' => 1, + 'subject' => '购买服务', + 'body' => '购买商品', + 'valid_time' => 3600, ]; - return $this->post('create_order',$data); - + return $this->post('create_order', $data); + } - + //查询订单 - private function query(){ - $data=[ - 'out_order_no'=>'2021110117254573565' + private function query() + { + $data = [ + 'out_order_no' => '2021110117254573565' ]; - $res=$this->post('query_order',$data,false); - echo json_encode($res);die; + $res = $this->post('query_order', $data, false); + echo json_encode($res); + die; } - + //订单退款 - private function refund(){ - $data=[ - 'out_order_no'=>'2021110118351347832', - 'out_refund_no'=>$this->order_number(), - 'reason'=>'退款原因', - 'refund_amount'=>1, + private function refund() + { + $data = [ + 'out_order_no' => '2021110118351347832', + 'out_refund_no' => $this->order_number(), + 'reason' => '退款原因', + 'refund_amount' => 1, ]; - $res=$this->post('create_refund',$data); - echo json_encode($res);die; + $res = $this->post('create_refund', $data); + echo json_encode($res); + die; } - + //订单分账 - private function settle(){ - $data=[ - 'out_order_no'=>'2021110118301265990', - 'out_settle_no'=>$this->order_number(), - 'settle_desc'=>'分账描述', - 'settle_params'=>json_encode([]),//分润方参数 如[['merchant_uid'=>'商户号','amount'=>'10']] 可以有多个分账商户 + private function settle() + { + $data = [ + 'out_order_no' => '2021110118301265990', + 'out_settle_no' => $this->order_number(), + 'settle_desc' => '分账描述', + 'settle_params' => json_encode([]),//分润方参数 如[['merchant_uid'=>'商户号','amount'=>'10']] 可以有多个分账商户 ]; - $res=$this->post('settle',$data); - echo json_encode($res);die; + $res = $this->post('settle', $data); + echo json_encode($res); + die; } - + //支付设置回调测试 - private function set(){ - $content=file_get_contents('php://input'); - $this->log('log.txt',$content); + private function set() + { + $content = file_get_contents('php://input'); + $this->log('log.txt', $content); } - + //回调 - private function notify(){ - $content=input(); - - if(empty($content)) return false; - $this->log('notify.txt',json_encode($content)); - - if(is_array($content)){ - $content=$content; - }else{ - $content=json_decode($content,true); + private function notify() + { + $content = input(); + + if (empty($content)) return false; + $this->log('notify.txt', json_encode($content)); + + if (is_array($content)) { + $content = $content; + } else { + $content = json_decode($content, true); } - - $sign=$this->handler($content); - if(!empty($content['msg_signature']) && $sign==$content['msg_signature']){ - - if(is_array($content['msg'])){ - $msg=$content['msg']; - }else{ - $msg=json_decode($content['msg'],true); + + $sign = $this->handler($content); + if (!empty($content['msg_signature']) && $sign == $content['msg_signature']) { + + if (is_array($content['msg'])) { + $msg = $content['msg']; + } else { + $msg = json_decode($content['msg'], true); } - - - if($content['type'] == 'payment'){ + + + if ($content['type'] == 'payment') { $order_sn = $msg['payment_order_no']; - Db::name('order')->where('order_sn',$order_sn)->update(['pay_status'=>1]); + Db::name('order')->where('order_sn', $order_sn)->update(['pay_status' => 1]); } - - + + //这里更新应用业务逻辑代码,使用$msg跟应用订单比对更新订单,可以用 $content['type']判断是支付回调还是退款回调,payment支付回调 refund退款回调。 - $res=['err_no'=>0,'err_tips'=>'success']; + $res = ['err_no' => 0, 'err_tips' => 'success']; echo json_encode($res); exit; - }else{ + } else { echo '验签失败'; } } - - + + /** - * 测试订单号,实际应用根据自己应用实际生成 - * @return string - */ - private function order_number(){ - return date('YmdHis').rand(10000,99999); + * 测试订单号,实际应用根据自己应用实际生成 + * @return string + */ + private function order_number() + { + return date('YmdHis') . rand(10000, 99999); } - - /** + + /** * 请求小程序平台服务端 * @param string $url 接口地址 * @param array $data 参数内容 * @param boolean $notify 是否有回调 * @return array - */ - private function post($method,$data,$notify=true){ - $data['app_id']=$this->app_id; - - $data['sign']=$this->sign($data); - $url=$this->api_url.$method; - $res=$this->http('POST',$url,json_encode($data),['Content-Type: application/json'],true); - return json_decode($res,true); + */ + private function post($method, $data, $notify = true) + { + $data['app_id'] = $this->app_id; + + $data['sign'] = $this->sign($data); + $url = $this->api_url . $method; + $res = $this->http('POST', $url, json_encode($data), ['Content-Type: application/json'], true); + return json_decode($res, true); } - + /** * 回调验签 * @param array $map 验签参数 * @return stirng - */ - private function handler($map){ + */ + private function handler($map) + { $rList = array(); array_push($rList, $this->token); - foreach($map as $k =>$v) { - if ( $k == "type" || $k=='msg_signature') + foreach ($map as $k => $v) { + if ($k == "type" || $k == 'msg_signature') continue; $value = trim(strval($v)); if ($value == "" || $value == "null") continue; array_push($rList, $value); } - sort($rList,2); + sort($rList, 2); return sha1(implode($rList)); } - + /** * 请求签名 * @param array $map 请求参数 * @return stirng - */ - private function sign($map) { + */ + private function sign($map) + { $rList = array(); - foreach($map as $k =>$v) { + foreach ($map as $k => $v) { if ($k == "other_settle_params" || $k == "app_id" || $k == "sign" || $k == "thirdparty_id") continue; $value = trim(strval($v)); $len = strlen($value); - if ($len > 1 && substr($value, 0,1)=="\"" && substr($value,$len, $len-1)=="\"") - $value = substr($value,1, $len-1); + if ($len > 1 && substr($value, 0, 1) == "\"" && substr($value, $len, $len - 1) == "\"") + $value = substr($value, 1, $len - 1); $value = trim($value); if ($value == "" || $value == "null") continue; @@ -854,40 +993,40 @@ Class ttPay{ return md5(implode('&', $rList)); } - /** + /** * 写日志 * @param string $path 日志路径 * @param string $content 内容 - */ - private function log($path, $content){ - $file=fopen($path, "a"); - fwrite($file, date('Y-m-d H:i:s').'-----'.$content."\n"); + */ + private function log($path, $content) + { + $file = fopen($path, "a"); + fwrite($file, date('Y-m-d H:i:s') . '-----' . $content . "\n"); fclose($file); } - - - - + + /** * 网络请求 * @param stirng $method 请求模式 - * @param stirng $url请求网关 + * @param stirng $url请求网关 * @param array $params 请求参数 - * @param stirng $header 自定义头 - * @param boolean $multi 文件上传 + * @param stirng $header 自定义头 + * @param boolean $multi 文件上传 * @return array */ - private function http( $method = 'GET', $url,$params,$header = array(), $multi = false){ - + private function http($method = 'GET', $url, $params, $header = array(), $multi = false) + { + $opts = array( - CURLOPT_TIMEOUT => 30, + CURLOPT_TIMEOUT => 30, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, - CURLOPT_HTTPHEADER => $header + CURLOPT_HTTPHEADER => $header ); /* 根据请求类型设置特定参数 */ - switch(strtoupper($method)){ + switch (strtoupper($method)) { case 'GET': $opts[CURLOPT_URL] = $url . '?' . http_build_query($params); break; @@ -901,17 +1040,17 @@ Class ttPay{ default: throw new Exception('不支持的请求方式!'); } - + /* 初始化并执行curl请求 */ $ch = curl_init(); curl_setopt_array($ch, $opts); - $data = curl_exec($ch); + $data = curl_exec($ch); $error = curl_error($ch); curl_close($ch); - if($error) throw new Exception('请求发生错误:' . $error); - return $data; + if ($error) throw new Exception('请求发生错误:' . $error); + return $data; } - - + + } diff --git a/application/api/logic/OrderLogic.php b/application/api/logic/OrderLogic.php index ea943261..81921abd 100644 --- a/application/api/logic/OrderLogic.php +++ b/application/api/logic/OrderLogic.php @@ -120,7 +120,9 @@ class OrderLogic extends LogicBase $order_amount += $total_shipping_price;//应付订单金额+运费 $total_amount += $total_shipping_price;//订单金额+运费 - + if ($post['goods_type'] == 4){ + self::$order_type = CommonOrder::GROUP_ORDER;//普通订单 + } $result = [ 'order_type' => self::$order_type, 'goods_lists' => array_values($goods_lists), @@ -951,7 +953,6 @@ class OrderLogic extends LogicBase $order = new Order(); $where[] = ['del', '=', 0]; // $where[] = ['user_id', '=', $user_id]; - switch ($type) { case 'pay': $where[] = ['pay_status', '=', CommonOrder::STATUS_WAIT_PAY]; @@ -987,9 +988,23 @@ class OrderLogic extends LogicBase $number=Db::name('order_exe')->where('order_sn',$list['order_sn'])->where('staff_status',3)->count(); //查询订单服务次数 $list['ordercs']=$number; $list['orderyjfw']= $list['number']-$number; + $list['orderdaifw'] = Db::name('order_exe')->where('order_sn',$list['order_sn'])->where('staff_status',0)->count(); //待服务数量 + $list['orderfwzhon'] = Db::name('order_exe')->where('order_sn',$list['order_sn'])->where('staff_status',1)->count(); //服务中数量 $list['showBubble']=false; $list['more']="更多"; } + /** + * order_status:订单状态 0-待付款;1-待发货;2-待收货;3-已完成;4-已关闭 + * pay_status:支付状态;0-待支付;1-已支付;2-已退款;3-拒绝退款 + * order_amount:应付款金额 + * order_type:订单类型;0-服务商品;1-秒杀订单;2-拼团订单;3-砍价订单;4-普通商品 + * shipping_status:发货状态 + * number:订单的总条数 + * code:订单的执行次数 + * goods_price:订单商品总价 + * ordercs:以订单服务次数 + * orderyjfw:订单的剩余执行次数 + */ $data = [ 'list' => $lists, 'page' => $page, diff --git a/application/common/model/Order.php b/application/common/model/Order.php index 20ba1f75..4fa3b578 100644 --- a/application/common/model/Order.php +++ b/application/common/model/Order.php @@ -10,10 +10,11 @@ class Order extends Model protected $name = 'order'; //订单类型 - const NORMAL_ORDER = 0;//普通订单 + const NORMAL_ORDER = 0;//服务订单 const SECKILL_ORDER = 1;//秒杀订单 const TEAM_ORDER = 2;//拼团订单 const BARGAIN_ORDER = 3;//砍价订单 + const GROUP_ORDER = 4; //普通订单 //订单状态 const STATUS_WAIT_PAY = 0; //待付款 @@ -52,6 +53,7 @@ class Order extends Model self::SECKILL_ORDER => '秒杀订单', self::TEAM_ORDER => '拼团订单', self::BARGAIN_ORDER => '砍价订单', + self::GROUP_ORDER => '普通订单', ]; if ($type === true){