getWarehouseVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } switch ($param['user_type']) { case 3: //商户 $WarehouseModel = new SaleWarehouseModel(); break; case 4: //门店 $WarehouseModel = new SSaleWarehouseModel(); break; } $where = $this->getSaleWarehouseTerm($param); //查询条件 $id = $WarehouseModel->getFindField($where, "id"); return callBack(statusCode()['success'], "查询成功", $id); } /** * 获取仓库的查询条件 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * ] * @return mixed */ public function getSaleWarehouseTerm($param) { $where = [ 'merchant_id' => $param['merchant_id'], 'status' => 1 ]; if ($param['user_type'] == 4) { $where['store_id'] = $param['store_id']; } return $where; } /** * 获取仓库id的参数验证 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * ] * @return mixed */ public function getWarehouseVerify($param) { if (empty($param['user_type']) || !in_array($param['user_type'], ['3', '4']) || empty($param['merchant_id']) || ($param['user_type'] == 4 && empty($param['store_id']))) { return callBack(statusCode()['error'], "未知身份"); } return callBack(statusCode()['success'], "验证成功"); } /** * 门店销售仓库的添加与编辑 * @param $param * [ * merchant_id 商户id * store_id * id 仓库id 编辑使用 * name 仓库名称 * number 仓库编号 * province 省 * city 市 * area 区 * address 详细地址 * measure_area 面积平方米 * person_name 负责人名称 * person_phone 负责人手机号 * ] * @return mixed */ public function storeSaleWarehouseOperation($param) { $verifyResult = $this->warehouseTerm($param); if ($verifyResult['status'] != 1) { return $verifyResult; } if (empty($param['store_id'])) { return callBack(statusCode()['error'], "缺少必要参数"); } $SSaleWarehouseModel = new SSaleWarehouseModel(); if (empty($param['id'])) { $info = $SSaleWarehouseModel->getFind([ 'merchant_id' => $param['merchant_id'], 'store_id' => $param['store_id'], 'status' => 1 ]); if (!empty($info)) { return callBack(statusCode()['error'], '已存在供给仓'); } } if (!empty($param['id'])) { //编辑 $id = $param['id']; unset($param['id']); $result = $SSaleWarehouseModel->updateData([ 'id' => $id ], $param); } else { //添加 unset($param['id']); $param['status'] = 1; $param['add_time'] = time(); $result = $SSaleWarehouseModel->addData($param); } if ($result['status'] == 1) { return callBack(statusCode()['success'], '操作成功'); } else { return callBack(statusCode()['error'], '暂无修改'); } } /** * 商户销售仓库的添加与编辑 * @param $param * [ * merchant_id 商户id * id 仓库id 编辑使用 * name 仓库名称 * number 仓库编号 * province 省 * city 市 * area 区 * address 详细地址 * measure_area 面积平方米 * person_name 负责人名称 * person_phone 负责人手机号 * ] * @return mixed */ public function merchantSaleWarehouseOperation($param) { $verifyResult = $this->warehouseTerm($param); if ($verifyResult['status'] != 1) { return $verifyResult; } $SaleWarehouseModel = new SaleWarehouseModel(); if (empty($param['id'])) { $info = $SaleWarehouseModel->getFind([ 'merchant_id' => $param['merchant_id'], 'status' => 1 ]); if (!empty($info)) { return callBack(statusCode()['error'], '已存在供给仓'); } } if (!empty($param['id'])) { //编辑 $id = $param['id']; unset($param['id']); $result = $SaleWarehouseModel->updateData([ 'id' => $id ], $param); } else { //添加 unset($param['id']); $param['status'] = 1; $param['add_time'] = time(); $result = $SaleWarehouseModel->addData($param); } if ($result['status'] == 1) { return callBack(statusCode()['success'], '操作成功'); } else { return callBack(statusCode()['error'], '暂无修改'); } } /** * 门店采购仓库的添加与编辑 * @param $param * [ * merchant_id 商户id * store_id * id 仓库id 编辑使用 * default_state 1 默认仓库 * name 仓库名称 * number 仓库编号 * province 省 * city 市 * area 区 * address 详细地址 * measure_area 面积平方米 * person_name 负责人名称 * person_phone 负责人手机号 * ] * @return mixed */ public function storePurchaseWarehouseOperation($param) { $verifyResult = $this->warehouseTerm($param); if ($verifyResult['status'] != 1) { return $verifyResult; } if (empty($param['store_id'])) { return callBack(statusCode()['error'], '缺少必要参数'); } $where = [ 'merchant_id' => $param['merchant_id'], 'store_id' => $param['store_id'], 'number' => $param['number'], 'status' => 1 ]; if (!empty($param['id'])) { //编辑 $where['id'] = ['neq', $param['id']]; } $SPurchaseWarehouseModel = new SPurchaseWarehouseModel(); $info = $SPurchaseWarehouseModel->getFind($where); //查询编号是否存在 if (!empty($info)) { return callBack(statusCode()['error'], '已存在该编号,请更改编号重新提交'); } if (!empty($param['id'])) { //编辑 $id = $param['id']; //仓库id unset($param['id']); $result = $SPurchaseWarehouseModel->updateData([ 'id' => $id ], $param); } else { //添加 unset($param['id']); $param['status'] = 1; $param['add_time'] = time(); $result = $SPurchaseWarehouseModel->addData($param); $id = $result['data']; //仓库id } if ($result['status'] == 1 && $param['default_state'] == 1) { $where = [ 'id' => ['neq', $id], 'merchant_id' => $param['merchant_id'], 'store_id' => $param['store_id'], 'status' => 1 ]; $SPurchaseWarehouseModel->updateData($where, [ 'default_state' => 0 ]); } if ($result['status'] == 1) { return callBack(statusCode()['success'], '操作成功'); } else { return callBack(statusCode()['error'], '暂无修改'); } } /** * 商户采购仓库的添加与编辑 * @param $param * [ * merchant_id 商户id * id 仓库id 编辑使用 * default_state 1 默认仓库 * name 仓库名称 * number 仓库编号 * province 省 * city 市 * area 区 * address 详细地址 * measure_area 面积平方米 * person_name 负责人名称 * person_phone 负责人手机号 * ] * @return mixed */ public function merchantPurchaseWarehouseOperation($param) { $verifyResult = $this->warehouseTerm($param); if ($verifyResult['status'] != 1) { return $verifyResult; } $where = [ 'merchant_id' => $param['merchant_id'], 'number' => $param['number'], 'status' => 1 ]; if (!empty($param['id'])) { //编辑 $where['id'] = ['neq', $param['id']]; } $PurchaseWarehouseModel = new PurchaseWarehouseModel(); $info = $PurchaseWarehouseModel->getFind($where); //查询编号是否存在 if (!empty($info)) { return callBack(statusCode()['error'], '已存在该编号,请更改编号重新提交'); } if (!empty($param['id'])) { //编辑 $id = $param['id']; unset($param['id']); $result = $PurchaseWarehouseModel->updateData([ 'id' => $id ], $param); } else { //添加 unset($param['id']); $param['status'] = 1; $param['add_time'] = time(); $result = $PurchaseWarehouseModel->addData($param); $id = $result['data']; } if ($result['status'] == 1 && $param['default_state'] == 1) { $where = [ 'id' => ['neq', $id], 'merchant_id' => $param['merchant_id'], 'status' => 1 ]; $PurchaseWarehouseModel->updateData($where, [ 'default_state' => 0 ]); } if ($result['status'] == 1) { return callBack(statusCode()['success'], '操作成功'); } else { return callBack(statusCode()['error'], '暂无修改'); } } /** * 仓库参数验证 * @param $param * [ * name 仓库名称 * number 仓库编号 * province 省 * city 市 * area 区 * address 详细地址 * measure_area 面积平方米 * person_name 负责人名称 * person_phone 负责人手机号 * ] * @return mixed */ public function warehouseTerm($param) { $reg = "/^([a-zA-z_]{1})([\w]*)$/"; if (empty($param['merchant_id'])) { return callBack(statusCode()['error'], '缺少必要参数'); } if (!isset($param['name']) || !isset($param['number']) || empty($param['province']) || empty($param['city']) || empty($param['area']) || empty($param['address']) || !isset($param['measure_area']) || empty($param['person_name']) || empty($param['person_phone'])) { return callBack(statusCode()['error'], '请完善表单信息'); } if (!preg_match($reg, $param['number'])) { return callBack(statusCode()['error'], '请输入正确的编号'); } return callBack(statusCode()['success'], '验证成功'); } }