model = new \app\common\model\ShopOrder(); } /** * @NodeAnotation(title="列表") */ public function index() { if ($this->request->isAjax()) { list($page, $limit, $where) = $this->buildTableParames(); list($count, $list) = ShopOrderLogic::getList($page, $limit, $where); $data = [ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); } /** * @NodeAnotation(title="修改备注") */ public function editdesc($id) { if ($this->request->isPost()) { $post = $this->request->post(); $row = $this->model->where('order_id', $id)->find(); empty($row) && $this->error('取消失败'); $row->order_remark = $post['error_text']; Db::startTrans(); try { $row->save(); Db::commit(); } catch (\Exception $e) { Db::rollback(); $this->error('设置失败' . $e->getMessage()); } $this->success('设置成功'); } $row = ShopOrderDao::getOrderById($id); $this->assign('info', $row); return $this->fetch(); } /** * @NodeAnotation(title="修改订单状态") */ public function editstatus($id) { if ($this->request->isPost()) { $post = $this->request->post(); try { validate(EditStatus::class)->check($post); } catch (ValidateException $e) { $this->error($e->getMessage()); } $result = ShopOrderLogic::editStatus($post['id'], $post['status']); if ($result !== true) { $this->error($result); } $this->success('修改订单状态成功'); } $row = $this->model->where('order_id', $id)->find(); $row['status_map'] = ShopOrderLogic::getStatusMap(); $this->assign('info', $row); return $this->fetch('editstatus'); } /** * @NodeAnotation(title="列表") */ public function details($orderId) { $order = $this->model->where(['order_id' => $orderId])->with(['user', 'goods', 'shipping'])->find()->toArray(); if ($order['status'] == 5 || $order['status'] == 6) { // 新的地址 $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find(); $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find(); $order['shipping']['sp_id'] = 99999; $order['shipping']['sp_mobile'] = $newAddress_info['mobile']; $order['shipping']['sp_name'] = $newAddress_info['name']; $order['shipping']['sp_mergename'] = $newAddress_info['mergename']; } $this->assign('data', $order); return $this->fetch(); } /** * 订单配送列表(疑似无效) * @NodeAnotation(title="列表") */ public function delivery($orderId) { $express = Db::name('express')->field('id,name,code')->select()->toArray(); $shipping = Db::name('shop_order_shipping')->where(['order_id' => $orderId])->findOrEmpty(); $order = Db::name('shop_order')->where('order_id', $shipping['order_id'])->find(); $this->assign('express', $express); if ($order['status'] == 5 || $order['status'] == 6) { // 新的地址 $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find(); $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find(); $shipping['sp_id'] = 99999; $shipping['sp_mobile'] = $newAddress_info['mobile']; $shipping['sp_name'] = $newAddress_info['name']; $shipping['sp_mergename'] = $newAddress_info['mergename']; } $this->assign('shipping', $shipping); return $this->fetch(); } /** * 订单配送设置物流信息(疑似无效) * @NodeAnotation(title="列表") */ public function deliverySave() { if ($this->request->isPost()) { $data = $this->request->post(); if (empty($data['order_id'])) { return json(['code' => 0, 'msg' => '参数错误']); } if (empty($data['ship_number']) || empty($data['ship_name'])) { return json(['code' => 0, 'msg' => '物流信息不能为空']); } $ex = explode('_', $data['ship_name']); // 发货 if ($order_info = Db::name('shop_order')->where(['order_id' => $data['order_id']])->where('status', 'in', [5])->find()) { $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]); $yg_orderinfo = Db::name('yg_order')->where('order_sn', $order_info['order_sn'])->find(); Db::name('yg_buy_record')->where('yg_id', $yg_orderinfo['id'])->where('status', 3)->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 4]); // 重新发货 } elseif ($order_info = Db::name('shop_order')->where(['order_id' => $data['order_id']])->where('status', 'in', [6])->find()) { $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]); $yg_orderinfo = Db::name('yg_order')->where('order_sn', $order_info['order_sn'])->find(); Db::name('yg_buy_record')->where('yg_id', $yg_orderinfo['id'])->where('status', 4)->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number']]); } else { $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 2]); } if (!$res) { return json(['code' => 0, 'msg' => '操作失败']); } return json(['code' => 1, 'msg' => '操作成功']); } } }