model = new \app\common\model\ShopOrder(); } /** * @NodeAnotation(title="列表") */ public function index () { if ($this->request->isAjax()) { // if (input('selectFields')) { // return $this->selectList(); // } // return json_decode(htmlspecialchars_decode($this->request->param('filter'))); // return $this->reque('filter'); // return json_decode(input('op')); list($page, $limit, $where) = $this->buildTableParames(); foreach ($where as $key=>$val){ if ($val[0] == 'status'){ $where[$key][0] = 'o.status'; } if ($val[0] == 'created_time'){ $where[$key][0] = 'o.created_time'; $where[$key][2] = sr_getcurtime($where[$key][2]); } if ($val[0] == 'order_type'){ $where[$key][0] = 'o.order_type'; } } $count = $this->model ->alias('o') ->with(['goods']) ->where($where) // ->where('o.status', '<>', 3) ->leftJoin('user u', 'u.id = o.user_id') ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id') ->field('o.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile') ->count(); $list = $this->model ->alias('o') ->with(['goods']) ->where($where) // ->where('o.status', '<>', 3) ->leftJoin('user u', 'u.id = o.user_id') ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id') ->field('o.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile') ->order('o.order_id desc') ->withAttr('order_sn', function($val, $data){ return '编号:'.$val; }) ->page($page, $limit) ->select()->toArray(); foreach ($list as $k => $v) { $goods_id = $v['goods'][0]['goods_id']; $goods_info = Db::name('shop_goods')->where('goods_id', $goods_id)->find(); if ($goods_info){ $list[$k]['cost_price'] = $goods_info['cost_price']; }else{ $list[$k]['cost_price'] = 0; } if ($v['status'] == 5 || $v['status'] == 6){ // 新的地址 $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $v['order_sn']))->find(); $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find(); $list[$k]['sp_id'] = 99999; $list[$k]['sp_mobile'] = $newAddress_info['mobile']; $list[$k]['sp_name'] = $newAddress_info['name']; $list[$k]['sp_mergename'] = $newAddress_info['mergename']; } } $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 = $this->model->where('order_id', $id)->find(); $this->assign('info', $row); return $this->fetch(); } /** * @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' => '操作成功']); } } }