field('id,status')->where('id', $id)->find(); if (!$info) { return $this->errorResponse(lang('request_method_incorrect')); } if ($status == 1) { $count0 = Db::name('third_party_stock_address')->where('third_party_stock_id', $id)->where('status', 0)->count(); if ($count0 > 0) { return $this->errorResponse('请先审核仓库地址'); } $count1 = Db::name('third_party_stock_address')->where('third_party_stock_id', $id)->where('status', 1)->count(); if ($count1 == 0) { return $this->errorResponse('至少有一个仓库地址通过审核'); } Db::name('third_party_stock')->where('id', $id)->update(['status' => 1, 'need_review' => 1]); $message = '操作成功,审核通过'; } else { Db::name('third_party_stock_address')->where('third_party_stock_id', $id)->where('status', 0)->save(['status' => 2]); Db::name('third_party_stock')->where('id', $id)->update(['status' => 2, 'need_review' => 1]); $message = '操作成功,审核不通过'; } // 提交事务 Db::commit(); return $this->successResponse($message); } else { return $this->errorResponse(lang('request_method_incorrect')); } } catch (Exception $exc) { // 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } /** * 审核仓库地址 * @return array|int[] */ public function reviewAddress() { // 开始数据库事务 Db::startTrans(); try { if (!Request::isPost()) { throw new Exception(lang('request_method_incorrect')); } $id = input('post.id'); if (is_numeric($id)) { $status = input('post.status'); $result = [ 'stock_status' => 0, 'status' => 0, 'need_review' => 0, ]; //更新数据 $info = Db::name('third_party_stock_address')->field('id,status,third_party_stock_id')->where('id', $id)->find(); if (!$info) { return $this->errorResponse(lang('request_method_incorrect')); } if ($status == 1) { Db::name('third_party_stock_address')->where('id', $id)->update(['status' => 1]); $result['status'] = 1; $result['message'] = '操作成功,审核通过'; } else { Db::name('third_party_stock_address')->where('id', $id)->update(['status' => 2]); $result['status'] = 2; $result['message'] = '操作成功,审核不通过'; } $count0 = Db::name('third_party_stock_address')->where('third_party_stock_id', $info['third_party_stock_id'])->where('status', 0)->count(); $count1 = Db::name('third_party_stock_address')->where('third_party_stock_id', $info['third_party_stock_id'])->where('status', 1)->count(); if ($count0 == 0) { //仓库地址全部审核 if ($count1 == 0) { //仓库不通过审核 Db::name('third_party_stock')->where('id', $info['third_party_stock_id'])->update(['need_review' => 1, 'status' => 2]); $result['need_review'] = 1; $result['stock_status'] = 2; } else { //仓库通过审核 Db::name('third_party_stock')->where('id', $info['third_party_stock_id'])->update(['need_review' => 1, 'status' => 1]); $result['need_review'] = 1; $result['stock_status'] = 1; } } // 提交事务 Db::commit(); return $this->successResponse($result); } else { return $this->errorResponse(lang('request_method_incorrect')); } } catch (Exception $exc) { // 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } /** * 获取仓库列表 */ public function stockList() { if (Request::isPost()) { $kw = input('kw'); if (!empty($kw)) { $condition[] = array('third_party_stock_name|docking_code', 'like', "%$kw%"); } // $condition[]= array('need_review', '=', 2); $p = input('p', 1); $_GET['p'] = $p; $other['page_size'] = input('page_size', 20); $order = 'need_review desc,edit_time asc'; $count = Db::name('third_party_stock')->where($condition)->count(); $list = Db::name('third_party_stock')->field("id,stock_type,docking_system,third_party_stock_name,docking_code,status,need_review,edit_time")->where($condition) ->withAttr('edit_time', function ($value, $data) { return date('Y-m-d H:i:s', $value); }) ->order($order)->page($p, $other['page_size'])->select()->toArray(); $other['count'] = $count; if (!$list) { $list = []; } $d['code'] = 200; $d['list'] = $list; $d['other'] = $other; return $d; } } /** * 获取仓库列表 */ public function stockAddressList() { if (Request::isPost()) { $third_party_stock_id = input('third_party_stock_id'); $condition['a.third_party_stock_id'] = $third_party_stock_id; $order = 'a.id asc'; $list = Db::name('third_party_stock_address') ->alias('a') ->join('web_stock_country b', 'a.stock_country_id=b.id') ->field("a.id,a.receive_man,a.tel,a.stock_address,a.stock_city,a.stock_province,a.stock_country_id,a.stock_post_code,a.suit_range,b.country,a.status")->where($condition) ->withAttr('suit_range', function ($value, $data) { return $value ? array_map('intval', explode(',', $value)) : []; }) ->order($order)->select()->toArray(); if (!$list) { $result['code'] = 400; return $result; } else { $result['code'] = 200; $result['list'] = $list; return $result; } } } }