fail('传入type'); if ($data['type'] == 1 and strstr($data['service_id'], '1')){ $address = get_address($data['hospital']); if (!strstr($data['transfer_address'], $address['city'])){ return app('json')->fail('接送地址和医院不在同一个市'); } } $price = 0;// 金额 $ot_price = 0; $commission = 0; //佣金 $card_id = []; $data['cate'] = explode(',', $data['cate']); foreach ($data['cate'] as $item){ $da = date('w'); if ($da == 0) $da = 7; $equity = UserEquity::where('c_id', 'like', '%'.$item.'%')->where('uid', $request->uid())->order('number DESC')->where('use', 1)->where('start_week', '<=', $da)->where('end_week', '>=', $da)->find(); $cate = DiagnosisCate::where('id', $item)->find(); if ($equity){ $price += 0; $card_id[] = $equity['user_card_id']; }else{ $price += $cate['price']; } $ot_price += $cate['price']; $commission += $cate['reward']; } if ($data['type'] == 2){ $ot_price += sys_config('basics_price'); } if ($data['type'] == 2 and !$card_id){ $price += sys_config('basics_price'); } $card_id = array_unique($card_id); if ($card_id){ $card_id = implode(',', $card_id); } if ($data['service_id']){ $data['service_id'] = explode(',', $data['service_id']); foreach ($data['service_id'] as $item){ $cate = DiagnosisService::where('id', $item)->find(); $price += $cate['price']; $ot_price += $cate['price']; $commission += $cate['reward']; } } $order['cate_id'] = implode(',', $data['cate']); $order['ot_price'] = $ot_price; $order['pay_price'] = $price; $order['commission'] = $commission; $order['type'] = $data['type']; $order['user_card_id'] = $card_id; if (strtotime($data['time']) < time()){ return app('json')->fail('选择正确的时间'); } $order['attr'] = [ 'uid' => $request->uid(), 'time' => strtotime($data['time']), 'service_id' => $data['service_id'] ? implode(',', $data['service_id']) : [], 'name' => $data['name'], 'sex' => $data['sex'], 'age' => $data['age'], 'phone' => $data['phone'], 'hospital' => $data['hospital'], 'urgent_phone' => $data['urgent_phone'], 'transfer_address' => $data['transfer_address'], 'remarks' => $data['remarks'], ]; list($msec, $sec) = explode(' ', microtime()); $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', ''); $orderId = $request->uid() . $msectime . mt_rand(10000, 99999); $order['cache'] = $orderId; cache($order['cache'], $order, 300); return app('json')->successful($order); } /** * 创建订单 * @param Request $request * @return mixed */ public function create(Request $request) { $data = UtilService::postMore([ ['cache', ''], ['pay_type' , ''] ]); $uid = $request->uid(); $order = cache($data['cache']); if (!$order) return app('json')->fail('订单已过期'); if (!$data['pay_type']) return app('json')->fail('支付方式不正确'); $orderInfo = DiagnosisOrder::create_order($order, $data['pay_type'],$uid); if ($order['pay_price'] == 0){ $res = DiagnosisOrder::yuPay($orderInfo['order_id']); if ($res){ cache()->delete($data['cache']); return app('json')->status('success', '支付成功'); }else{ return app('json')->fail('支付失败'); } }else{ if ($orderInfo['pay_type'] == 1){ $res = DiagnosisOrder::yuPay($orderInfo['order_id']); if ($res){ cache()->delete($data['cache']); return app('json')->status('success', '余额支付成功'); }else{ return app('json')->fail('支付失败'); } }elseif ($orderInfo['pay_type'] ==2){ try { $jsConfig = OrderRepository::jsDiaPay($orderInfo['order_id']); //创建订单jspay } catch (\Exception $e) { return app('json')->status('pay_error', $e->getMessage()); } $info['jsConfig'] = $jsConfig; cache()->delete($data['cache']); return app('json')->status('wechat_pay', '订单创建成功', $info); }elseif ($orderInfo['pay_type'] ==3){ try { $jsConfig = OrderRepository::wxDiaPay($orderInfo['order_id']); //创建订单jspay } catch (\Exception $e) { return app('json')->status('pay_error', $e->getMessage()); } $info['jsConfig'] = $jsConfig; cache()->delete($data['cache']); return app('json')->status('wechat_h5_pay', '订单创建成功', $info); } } return app('json')->fail('订单生成失败!'); } /** * 用户订单 * @param Request $request * @return mixed */ public function order_list(Request $request) { $data = UtilService::getMore([ ['status', ''], ['page', 1], ['limit', 10] ]); $list = DiagnosisOrder::alias('a') ->field('a.*,b.time,b.name,b.sex,b.age,b.phone,b.hospital,b.urgent_phone,b.service_id,b.transfer_address,b.remarks') ->leftJoin('diagnosis_order_attr b', 'a.id = b.oid') ->order('a.id DESC') ->where('a.paid', 1) ->where('a.status', $data['status']) ->where('a.uid', $request->uid()) ->page($data['page'], $data['limit'])->select(); $list = count($list) > 0 ? $list->toArray() : []; if ($list){ foreach ($list as &$item){ $item['images'] = json_decode($item['images']); $item['after_images'] = json_decode($item['after_images']); $item['cate'] = DiagnosisCate::where('id', 'in', $item['cate_id'])->column('name'); $item['service'] = DiagnosisService::where('id', 'in', $item['service_id'])->column('name'); $item['receiving'] = DiagnosisApply::where('uid', $item['order_receiving'])->find(); } } return app('json')->successful($list); } /** * 订单详情 * @param Request $request * @return void */ public function details(Request $request,$id) { if (!$id) return app('json')->fail('传入订单id!'); $list = DiagnosisOrder::alias('a') ->field('a.*,b.time,b.name,b.sex,b.age,b.phone,b.hospital,b.urgent_phone,b.service_id,b.transfer_address,b.remarks') ->leftJoin('diagnosis_order_attr b', 'a.id = b.oid') ->order('a.id DESC') ->where('a.id', $id) ->find()->toArray(); $list['images'] = json_decode($list['images']); $list['after_images'] = json_decode($list['after_images']); $list['cate'] = DiagnosisCate::where('id', 'in', $list['cate_id'])->column('name'); $list['service'] = DiagnosisService::where('id', 'in', $list['service_id'])->column('name'); $list['receiving'] = DiagnosisApply::where('uid', $list['order_receiving'])->find(); return app('json')->successful($list); } /** * 接单 * @param Request $request * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function order_receiving(Request $request,$id) { BaseModel::beginTrans(); $user = User::where('uid', $request->uid())->find(); if ($user['is_receiver'] != 1) return app('json')->fail('你不是接单员'); if (!$id) return app('json')->fail('传入订单id!'); $order = DiagnosisOrder::where('id', $id)->lock(true)->find(); if ($order['status'] < 0) return app('json')->fail('订单已取消'); if ($order['status'] > 0) return app('json')->fail('该订单已被接'); $order['order_receiving'] = $request->uid(); $order['status'] = 1; $res = $order->save(); if ($res){ BaseModel::commitTrans(); return app('json')->success('接单成功'); } BaseModel::rollbackTrans(); return app('json')->fail('接单失败'); } /** * 接单员订单列表 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function receiving_list(Request $request) { $data = UtilService::getMore([ ['status', ''], ['page', 1], ['limit', 10] ]); $list = DiagnosisOrder::alias('a') ->field('a.*,b.time,b.name,b.sex,b.age,b.phone,b.hospital,b.urgent_phone,b.service_id,b.transfer_address,b.remarks') ->leftJoin('diagnosis_order_attr b', 'a.id = b.oid') ->order('a.id DESC') ->where('a.paid', 1) ->where('a.status', $data['status']) ->where('a.order_receiving', $request->uid()) ->page($data['page'], $data['limit'])->select(); $list = count($list) > 0 ? $list->toArray() : []; if ($list){ foreach ($list as &$item){ $item['images'] = json_decode($item['images']); $item['after_images'] = json_decode($item['after_images']); $item['cate'] = DiagnosisCate::where('id', 'in', $item['cate_id'])->column('name'); $item['service'] = DiagnosisService::where('id', 'in', $item['service_id'])->column('name'); $item['receiving'] = DiagnosisApply::where('uid', $item['order_receiving'])->find(); } } return app('json')->successful($list); } /** * 接单大厅 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function order_receiving_hall(Request $request) { $data = UtilService::getMore([ ['type'], ['page', 1], ['limit', 10], ]); if (!$data['type']) return app('json')->fail('传入类型'); $list = DiagnosisOrder::alias('a') ->field('a.*,b.time,b.name,b.sex,b.age,b.phone,b.hospital,b.urgent_phone,b.service_id,b.transfer_address,b.remarks') ->leftJoin('diagnosis_order_attr b', 'a.id = b.oid') ->order('a.id DESC') ->where('a.paid', 1) ->where('a.type', $data['type']) ->where('a.status', 0) ->page($data['page'], $data['limit'])->select(); $list = count($list) > 0 ? $list->toArray() : []; if ($list){ foreach ($list as &$item){ $item['images'] = json_decode($item['images']); $item['after_images'] = json_decode($item['after_images']); $item['cate'] = DiagnosisCate::where('id', 'in', $item['cate_id'])->column('name'); $item['service'] = DiagnosisService::where('id', 'in', $item['service_id'])->column('name'); $item['receiving'] = DiagnosisApply::where('uid', $item['order_receiving'])->find(); } } return app('json')->successful($list); } /** * 放弃订单 * @param Request $request * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException、 */ public function discard_order(Request $request,$id) { if (!$id) return app('json')->fail('传入订单id!'); $order = DiagnosisOrder::where('id', $id)->where('order_receiving', $request->uid())->lock(true)->find(); if (!$order) return app('json')->fail('订单不存在!'); $order['status'] = 0; $order['order_receiving'] = 0; $res = $order->save(); if ($res) return app('json')->success('放弃订单成功'); return app('json')->fail('放弃订单失败'); } /** * 取消订单 * @param Request $request * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function cancel_order(Request $request,$id) { if (!$id) return app('json')->fail('传入订单id!'); $order = DiagnosisOrder::where('id', $id)->where('uid', $request->uid())->find(); if (!$order) return app('json')->fail('订单不存在!'); if ($order['status'] > 2) return app('json')->fail('订单已完成无法取消!'); $order['status'] = -1; $res = $order->save(); if ($res) return app('json')->success('取消订单成功'); return app('json')->fail('取消订单失败'); } /** * 提交完成 * @param Request $request * @param $id * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function submit(Request $request,$id) { $data = UtilService::postMore([ ['images', ''] ]); if (!$id) return app('json')->fail('传入订单id!'); $order = DiagnosisOrder::where('id', $id)->where('order_receiving', $request->uid())->find(); if (!$order) return app('json')->fail('订单不存在!'); if ($order['status'] <> 1) return app('json')->fail('当前订单状态不对'); $order['images'] = json_encode($data['images']); $order['status'] = 2; $order['up_time'] = time(); $res = $order->save(); if ($res) return app('json')->success('提交订单成功'); return app('json')->fail('提交订单失败'); } /** * 用户确认完成 * @param Request $request * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function confirmation(Request $request,$id) { if (!$id) return app('json')->fail('传入订单id!'); BaseModel::beginTrans(); $order = DiagnosisOrder::where('id', $id)->where('uid', $request->uid())->lock(true)->find(); if (!$order) return app('json')->fail('订单不存在!'); if ($order['status'] <> 2) return app('json')->fail('当前订单状态不对'); $order['status'] = 3; if ($order['after_sales'] == 1){ $order['after_sales'] = 0; } $res1 = $order->save(); $user = User::where('uid', $order['order_receiving'])->find(); $res2 = UserBill::income('完成订单佣金', $order['order_receiving'], 'now_money', 'brokerage', $order['commission'], '', $user['brokerage_price']+$order['commission'], '完成订单佣金'); $res3 = User::where('uid', $order['order_receiving'])->inc('brokerage_price', $order['commission'])->update(); if ($res1 && $res2 && $res3){ BaseModel::commitTrans(); return app('json')->success('成功'); } BaseModel::rollbackTrans(); return app('json')->fail('失败'); } /** * 申请售后 * @param Request $request * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function after_sales(Request $request,$id) { $data = UtilService::postMore([ ['after_remarks'], ['after_images'] ]); if (!$id) return app('json')->fail('传入订单id!'); $order = DiagnosisOrder::where('id', $id)->where('uid', $request->uid())->lock(true)->find(); if (!$order) return app('json')->fail('订单不存在!'); if (empty($data['after_images'])) return app('json')->fail('传入售后图片!'); // if ($order['status'] <> 3) return app('json')->fail('订单未完成'); $order['after_remarks'] = $data['after_remarks']; $order['after_images'] = json_encode($data['after_images']); $order['after_sales'] = 1; $res = $order->save(); if ($res) return app('json')->success('提交成功'); return app('json')->fail('提交失败'); } }