enterpriseId = $enterpriseId; $this->userCenterId = $userCenterId; $this->objDMerchantApply = new DMerchantApply(); $this->objDMerchantSetting = new DMerchantSetting(); $this->objDShop = new DShop(); $this->objDShop->setTable('qianniao_shop_' . ceil($this->enterpriseId / $this->cutTable)); } /** * 入驻添加 * @param $params * @return ResultWrapper */ public function addApply($params) { $dbResult = $this->objDMerchantApply->get(['userCenterId' => $params['userCenterId'], 'deleteStatus' => StatusCode::$standard]); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } if (!empty($dbResult)) { return ResultWrapper::fail('您已经申请过了', ErrorCode::$paramError); } //商户申请资料 $insert = $params; if (isset($params['info'])) { $insert['info'] = json_encode($params['info']); } $insert['enterpriseId'] = $this->enterpriseId; $insert['auditStatus'] = StatusCode::$auditStatus['auditing']; $insert['enabledStatus'] = StatusCode::$standard; $insert['deleteStatus'] = StatusCode::$standard; $insert['createTime'] = time(); $insert['updateTime'] = time(); $dbResult = $this->objDMerchantApply->insert($insert); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 入驻审核 * @param $update * @param $where * @return ResultWrapper * @throws \Exception */ public function auditApply($update, $where) { //查询入驻 $dbResult = $this->objDMerchantApply->get($where); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } $apply = $dbResult; unset($dbResult); if (empty($apply)) { return ResultWrapper::fail('入驻信息为空', ErrorCode::$paramError); } //判断审核 if (isset($update['auditStatus']) && $update['auditStatus'] == StatusCode::$auditStatus['auditPass']) { //审核通过 //修改入驻状态 $update['auditStatus'] = StatusCode::$auditStatus['auditPass']; $update['auditTime'] = time(); //创建关联数据 $params = array_merge($apply, $update); $modelResult = self::createMerchantBindData($params); if (!$modelResult->isSuccess()) { return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode()); } $update['extend'] = $modelResult->getData(); } $dbResult = $this->objDMerchantApply->update($update, $where); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 创建商户关联创建数据 * @param $params * @return ResultWrapper * @throws \Exception */ public function createMerchantBindData($params) { //1.查询user表 $objDUserCenter = new DUserCenter(); $dbResult = $objDUserCenter->get(['id' => $params['userCenterId']]); if ($dbResult === false) { return ResultWrapper::fail($objDUserCenter->error(), ErrorCode::$paramError); } $user = $dbResult; unset($dbResult); if (empty($user)) { return ResultWrapper::fail('userCenter数据为空', ErrorCode::$paramError); } //1.1判断user数据 修改userCenter表客户来源状态 改为后台客户 增加默认密码 $password = 88888888; $return = '当前登录手机号已经注册后台, 已成功绑定商户'; if ($user['isCustomer'] == StatusCode::$customerType['customer']) { $userUpdate = [ 'password' => password_hash($password, PASSWORD_DEFAULT), 'isCustomer' => StatusCode::$customerType['user'], 'updateTime' => time() ]; $dbResult = $objDUserCenter->update($userUpdate, ['id' => $params['userCenterId']]); if ($dbResult === false) { return ResultWrapper::fail($objDUserCenter->error(), ErrorCode::$paramError); } $return = '当前登录手机号未注册, 已自动注册, 商户绑定成功, 默认密码:' . $password; } //3.增加企业绑定user表数据 把该userCenterId绑定为商户 $objDUserBindEnterprise = new DUserBindEnterprise(); $enterpriseBindData = [ 'userCenterId' => $params['userCenterId'], 'enterpriseId' => $this->enterpriseId, 'merchantId' => $params['id'], 'shopId' => 0, 'roleType' => StatusCode::$roleType['merchant'], 'updateTime' => time(), 'createTime' => time(), ]; $dbResult = $objDUserBindEnterprise->get(['enterpriseId' => $enterpriseBindData['enterpriseId'], 'userCenterId' => $enterpriseBindData['userCenterId'], 'roleType' => $enterpriseBindData['roleType']]); if ($dbResult === false) { return ResultWrapper::fail($objDUserBindEnterprise->error(), ErrorCode::$dberror); } $bind = $dbResult; unset($dbResult); if (empty($bind)) { $dbResult = $objDUserBindEnterprise->insert($enterpriseBindData); if ($dbResult === false) { return ResultWrapper::fail($objDUserBindEnterprise->error(), ErrorCode::$dberror); } } return ResultWrapper::success($return); } /** * 新增商户 * @param $params * @return ResultWrapper */ public function addMerchant($params) { $insertData = [ 'enterpriseId' => $this->enterpriseId, 'name' => $params['name'], 'contactName' => $params['contactName'], 'contactMobile' => $params['contactMobile'], ]; isset($params['desc']) && $insertData['desc'] = !empty($params['desc']) ? $params['desc'] : ''; isset($params['category']) && $insertData['category'] = !empty($params['category']) ? $params['category'] : ''; isset($params['provinceCode']) && $insertData['provinceCode'] = !empty($params['provinceCode']) ? $params['provinceCode'] : ''; isset($params['cityCode']) && $insertData['cityCode'] = !empty($params['cityCode']) ? $params['cityCode'] : ''; isset($params['districtCode']) && $insertData['districtCode'] = !empty($params['districtCode']) ? $params['districtCode'] : ''; isset($params['address']) && $insertData['address'] = !empty($params['address']) ? $params['address'] : ''; isset($params['note']) && $insertData['note'] = !empty($params['note']) ? $params['note'] : ''; isset($params['settleType']) && $insertData['settleType'] = !empty($params['settleType']) ? $params['settleType'] : ''; isset($params['settle']) && $insertData['settle'] = !empty($params['settle']) ? json_encode($params['settle']) : ''; isset($params['auditType']) && $insertData['auditType'] = !empty($params['auditType']) ? $params['auditType'] : ''; isset($params['audit']) && $insertData['audit'] = !empty($params['audit']) ? json_encode($params['audit']) : ''; isset($params['settingType']) && $insertData['settingType'] = !empty($params['settingType']) ? $params['settingType'] : ''; isset($params['setting']) && $insertData['setting'] = !empty($params['setting']) ? json_encode($params['setting']) : ''; $insertData['createTime'] = time(); $insertData['deleteStatus'] = StatusCode::$standard; $insertData['enabledStatus'] = StatusCode::$standard; $insertData['auditStatus'] = StatusCode::$auditStatus['auditPass']; $insertData['auditTime'] = time(); $password = '88888888'; if (!isset($params['userCenterMobile'])) { return ResultWrapper::fail('userCenterMobile参数错误', ErrorCode::$paramError); } $objMUserCenterRegister = new MUserCenterRegister(); $modelResult = $objMUserCenterRegister->mobileBindStatus($params['userCenterMobile'], $this->enterpriseId, StatusCode::$roleType['merchant']); if (!$modelResult->isSuccess()) { return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode()); } $userCenterId = $modelResult->getData(); unset($modelResult); if (!empty($userCenterId)) { return ResultWrapper::fail('登录手机号已经是商户', ErrorCode::$paramError); } //1.创建后台账户 $objDUserCenter = new DUserCenter(); $dbResult = $objDUserCenter->get(['mobile' => $params['userCenterMobile']]); if ($dbResult === false) { return ResultWrapper::fail($objDUserCenter->error(), ErrorCode::$dberror); } $user = $dbResult; unset($dbResult); if (empty($user)) { $userInsert = [ 'mobile' => $params['userCenterMobile'], 'password' => password_hash($password, PASSWORD_DEFAULT), 'deleteStatus' => StatusCode::$standard, 'source' => StatusCode::$source['manage'], 'isCustomer' => StatusCode::$customerType['user'], 'createTime' => time(), 'updateTime' => time(), ]; $dbResult = $objDUserCenter->insert($userInsert); if ($dbResult === false) { return ResultWrapper::fail($objDUserCenter->error(), ErrorCode::$dberror); } $insertData['userCenterId'] = $dbResult; $return = '该登录手机号未注册, 已自动注册, 密码:' . $password; } else { $insertData['userCenterId'] = $user['id']; $return = '该登录手机号已经注册, 已成功绑定商户'; } //2.创建商户 $dbResult = $this->objDMerchantApply->insert($insertData); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } $insertData['id'] = $dbResult; //3.创建角色绑定数据 $modelResult = self::createMerchantBindData($insertData); if (!$modelResult->isSuccess()) { return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode()); } return ResultWrapper::success($return); } /** * 修改商户 * @param $update * @param $where * @return ResultWrapper */ public function updateMerchant($update, $where = []) { $dbResult = $this->objDMerchantApply->get($where); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$paramError); } $merchant = $dbResult; if (empty($merchant)) { return ResultWrapper::fail('修改数据不存在', ErrorCode::$paramError); } $where['enterpriseId'] = $this->enterpriseId; unset($update['enterpriseId']); $update['updateTime'] = time(); if (isset($update['deleteStatus']) && $update['deleteStatus'] == StatusCode::$delete) { $update['deleteTime'] = time(); } if (isset($update['auditStatus']) && $update['auditStatus'] == StatusCode::$auditStatus['auditPass']) { $update['auditTime'] = time(); } if (isset($update['enabledStatus'])) { if($merchant['enabledStatus'] == StatusCode::$delete){ $update['enabledStatus'] = StatusCode::$standard; }else{ $update['enabledStatus'] = StatusCode::$delete; } } $updateShopData = []; if(isset($update['name']) && !empty($update['name']) && $merchant['name'] != $update['name']){ $updateShopData['name'] = $update['name']; } //获取仓库 if(isset($update['warehouseId']) && !empty($update['warehouseId'])){ if(is_array($update['warehouseId'])){ $warehouseId = $update['warehouseId']; $update['warehouseId'] = implode(',',$update['warehouseId']); }else{ $warehouseId = [$update['warehouseId']]; } $objMWarehouse = new MWarehouse($this->enterpriseId); $modelResult = $objMWarehouse->selectWarehouse(['id' => $warehouseId, 'deleteStatus' => StatusCode::$standard]); if(!$modelResult->isSuccess()){ return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode()); } $warehouseResult = $modelResult->getData(); unset($modelResult); if(empty($warehouseResult)){ return ResultWrapper::fail('仓库查询失败', ErrorCode::$paramError); } $selectWarehouseId = array_column($warehouseResult, 'id'); foreach($warehouseId as $value){ if(!in_array($value,$selectWarehouseId)){ return ResultWrapper::fail($value.'仓库查询失败', ErrorCode::$paramError); } } $updateShopData['warehouseId'] = $update['warehouseId']; } if(!empty($updateShopData)){ $objMShop = new MShop($this->enterpriseId, $this->userCenterId); $modelResult = $objMShop->updateShopData($updateShopData, ['enterpriseId' => $this->enterpriseId, 'merchantId' => $where['id'], 'deleteStatus' => 5]); if(!$modelResult->isSuccess()){ return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode()); } } unset($update['warehouseId']); unset($update['userCenterMobile']); $dbResult = $this->objDMerchantApply->update($update, $where); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 修改申请 * @param $update * @param $where * @return ResultWrapper */ public function updateApply($update, $where = []) { $dbResult = $this->objDMerchantApply->get($where); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$paramError); } if (empty($dbResult)) { return ResultWrapper::fail('修改数据不存在', ErrorCode::$paramError); } if ($dbResult['auditStatus'] == StatusCode::$auditStatus['auditPass']) { return ResultWrapper::fail('审核通过不可以修改', ErrorCode::$paramError); } $where['enterpriseId'] = $this->enterpriseId; unset($update['enterpriseId']); $update['updateTime'] = time(); $update['auditStatus'] = StatusCode::$auditStatus['auditing']; if (isset($update['info']) && !empty($update['info'])) { $update = json_encode($update['info']); } else { unset($update['info']); } $update['auditFailReason'] = ''; $dbResult = $this->objDMerchantApply->update($update, $where); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 商户列表 * @param $params * @return ResultWrapper */ public function getAllMerchant($params = []) { $buildSql = self::buildSqlBySelectParams($params); $returnData = $this->objDMerchantApply->query($buildSql['sql']); if ($returnData === false){ return ResultWrapper::fail($this->objDMerchantApply->error(),ErrorCode::$dberror); } $merchantIds = []; foreach ($returnData as &$value) { !empty($value['settle']) && $value['settle'] = json_decode($value['settle'], true); !empty($value['audit']) && $value['audit'] = json_decode($value['audit'], true); !empty($value['setting']) && $value['setting'] = json_decode($value['setting'], true); !empty($value['info']) && $value['info'] = json_decode($value['info'], true); $value['materielNum'] = 0; $value['orderNum'] = 0; $value['subPayMoney'] = 0; $merchantIds[] = $value['id']; } unset($value); $dbResult = $this->objDMerchantApply->query($buildSql['countSql']); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } $count = $dbResult; unset($dbResult); $objMShop = new MShop($this->enterpriseId,$this->userCenterId); $shopMapResult = $objMShop->getShopIdByMerchantIds($merchantIds); if (!$shopMapResult->isSuccess()){ return ResultWrapper::fail($shopMapResult->getData(),$shopMapResult->getErrorCode()); } $shopMap = $shopMapResult->getData(); foreach ($returnData as &$value){ $value['shopId'] = isset($shopMap[$value['id']]) ? $shopMap[$value['id']]['id'] : 0; } unset($value); $return = [ 'data' => self::formatMerchant($returnData), 'total' => isset($count[0]['total']) ? $count[0]['total'] : 0, ]; return ResultWrapper::success($return); } /** * 商户列表不分页 * @param $params * @return ResultWrapper */ public function getAllMerchantList() { $where = [ 'enterpriseId' => $this->enterpriseId, 'deleteStatus' => StatusCode::$standard, 'enabledStatus' => StatusCode::$standard, 'auditStatus' => StatusCode::$auditStatus['auditPass'] ]; $dbResult = $this->objDMerchantApply->select($where,'*',"createTime desc"); if ($dbResult === false){ return ResultWrapper::fail($this->objDMerchantApply->error(),ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * Doc: (des="") * User: XMing * Date: 2020/12/30 * Time: 10:24 上午 * @param $params * @return ResultWrapper * @throws \Exception */ public function getAll($params): ResultWrapper { $buildSql = self::buildSqlBySelectParams($params); $returnData = $this->objDMerchantApply->query($buildSql['sql']); if ($returnData === false){ return ResultWrapper::fail($this->objDMerchantApply->error(),ErrorCode::$dberror); } $merchantIds = []; foreach ($returnData as $val){ $merchantIds[] = $val['id']; } $objMSysAreaChina = new MSysAreaChina(); $objMShop = new MShop($this->enterpriseId,$this->userCenterId); $shopMapResult = $objMShop->getShopIdByMerchantIds($merchantIds); if (!$shopMapResult->isSuccess()){ return ResultWrapper::fail($shopMapResult->getData(),$shopMapResult->getErrorCode()); } $shopMap = $shopMapResult->getData(); $objMGoods = new MGoods($this->enterpriseId,true,$this->userCenterId); foreach ($returnData as &$value) { $value['shopId'] = isset($shopMap[$value['id']]) ? $shopMap[$value['id']]['id'] : 0; $value['logo'] = isset($shopMap[$value['id']]) ? $shopMap[$value['id']]['logo'] : ''; !empty($value['settle']) && $value['settle'] = json_decode($value['settle'], true); !empty($value['audit']) && $value['audit'] = json_decode($value['audit'], true); !empty($value['setting']) && $value['setting'] = json_decode($value['setting'], true); !empty($value['info']) && $value['info'] = json_decode($value['info'], true); if (!empty($value['provinceCode']) && !empty($value['cityCode']) && !empty($value['districtCode'])) { $areaName = $objMSysAreaChina->getNameByCode([$value['provinceCode'], $value['cityCode'], $value['districtCode']]); $value['area']['provinceName'] = isset($areaName[$value['provinceCode']]) ? $areaName[$value['provinceCode']] : ''; $value['area']['cityName'] = isset($areaName[$value['cityCode']]) ? $areaName[$value['cityCode']] : ''; $value['area']['districtName'] = isset($areaName[$value['districtCode']]) ? $areaName[$value['districtCode']] : ''; $value['area']['address'] = $value['address']; } $inSaleNumResult = $objMGoods->getInSaleNum($value['shopId']); if (!$inSaleNumResult->isSuccess()){ return ResultWrapper::fail($inSaleNumResult->getData(),$inSaleNumResult->getErrorCode()); } $goodsResult = $objMGoods->search([ 'shopId' => $value['shopId'], 'offset' => 0, 'limit' => 3, 'areaCode' => $params['areaCode'] ]); if (!$goodsResult->isSuccess()){ return ResultWrapper::fail($goodsResult->getData(),$goodsResult->getErrorCode()); } $goodsLists = $goodsResult->getData(); $value['goodsLists'] = $goodsLists['data']; $value['inSaleGoodsNum'] = (int)$inSaleNumResult->getData(); $value['distance'] = 1000;//单位m } $count = $this->objDMerchantApply->query($buildSql['countSql']); if ($count === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } $return = [ 'data' => $returnData, 'total' => isset($count[0]['total']) ? $count[0]['total'] : 0, ]; return ResultWrapper::success($return); } /** * Doc: (des="") * User: XMing * Date: 2020/12/30 * Time: 10:21 上午 * @param array $params * @return string[] */ public function buildSqlBySelectParams(array $params): array { $fields = ' * '; $countField = ' COUNT(id) AS total '; $tableName = $this->objDMerchantApply->get_Table(); $whereSql = ' WHERE enterpriseId = ' . $this->enterpriseId; if (isset($params['keyword'])) { $whereSql .= ' and name like "%' . $params['keyword'] . '%" '; } if (isset($params['deleteStatus'])) { $whereSql .= ' and deleteStatus = ' . $params['deleteStatus']; } if (isset($params['auditStatus'])) { $whereSql .= ' and auditStatus = ' . $params['auditStatus']; } if (isset($params['enabledStatus'])) { $whereSql .= ' and enabledStatus = ' . $params['enabledStatus']; } if (isset($params['starExpireTime']) && isset($params['endExpireTime'])) { $whereSql .= ' and expireTime between ' . $params['starExpireTime'] . ' and ' . $params['endExpireTime']; } if (isset($params['starCreateTime']) && isset($params['endCreateTime'])) { $whereSql .= ' and createTime between ' . $params['starCreateTime'] . ' and ' . $params['endCreateTime']; } if (isset($params['starAuditTime']) && isset($params['endAuditTime'])) { $whereSql .= ' and auditTime between ' . $params['starAuditTime'] . ' and ' . $params['endAuditTime']; } if (isset($params['starDeleteTime']) && isset($params['endDeleteTime'])) { $whereSql .= ' and deleteTime between ' . $params['starDeleteTime'] . ' and ' . $params['endDeleteTime']; } if (isset($params['search']) && !empty($params['search'])){ $search = '"%'.$params['search'].'%"'; $whereSql .= ' AND name LIKE '.$search; } $orderSql = ' order by createTime desc'; $limitSql = ' limit ' . $params['offset'] . ',' . $params['limit']; $sql = 'SELECT '.$fields.' FROM ' . $tableName . $whereSql . $orderSql . $limitSql; $countSql = 'SELECT '.$countField.' FROM '. $tableName . $whereSql; return [ 'sql' => $sql, 'countSql' => $countSql ]; } /** * 商户详情 * @param $params * @return ResultWrapper */ public function getInfoMerchant($params) { $params['deleteStatus'] = StatusCode::$standard; $params['enterpriseId'] = $this->enterpriseId; $dbResult = $this->objDMerchantApply->get($params); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } if (empty($dbResult)) { return ResultWrapper::success($dbResult); } !empty($dbResult['settle']) && $dbResult['settle'] = json_decode($dbResult['settle'], true); !empty($dbResult['audit']) && $dbResult['audit'] = json_decode($dbResult['audit'], true); !empty($dbResult['setting']) && $dbResult['setting'] = json_decode($dbResult['setting'], true); !empty($dbResult['info']) && $dbResult['info'] = json_decode($dbResult['info'], true); $objMSysAreaChina = new MSysAreaChina(); if (!empty($dbResult['provinceCode']) && !empty($dbResult['cityCode']) && !empty($dbResult['districtCode'])) { $areaName = $objMSysAreaChina->getNameByCode([$dbResult['provinceCode'], $dbResult['cityCode'], $dbResult['districtCode']]); $dbResult['area']['provinceName'] = isset($areaName[$dbResult['provinceCode']]) ? $areaName[$dbResult['provinceCode']] : ''; $dbResult['area']['cityName'] = isset($areaName[$dbResult['cityCode']]) ? $areaName[$dbResult['cityCode']] : ''; $dbResult['area']['districtName'] = isset($areaName[$dbResult['districtCode']]) ? $areaName[$dbResult['districtCode']] : ''; $dbResult['area']['address'] = $dbResult['address']; } $objDUserCenter = new DUserCenter(); $user = $objDUserCenter->get(['id' => $dbResult['userCenterId']]); if ($user === false) { return ResultWrapper::fail($objDUserCenter->error(), ErrorCode::$dberror); } if (empty($user)) { return ResultWrapper::fail('userCenter数据查询失败', ErrorCode::$dberror); } $dbResult['mobile'] = $user['mobile']; $dbResult = self::formatMerchant($dbResult); return ResultWrapper::success($dbResult); } /** * 格式化商户 * @param $params * @return array|mixed */ public function formatMerchant($params) { if(isset($params['id'])){ $data = [$params]; }else{ $data = $params; } $merchantIds = []; foreach ($data as $value) { $merchantIds[] = $value['id']; } $objMShop = new MShop($this->enterpriseId, $this->userCenterId); $modelResult = $objMShop->getShopData(['enterpriseId' => $this->enterpriseId, 'merchantId' => $merchantIds]); $shopResult = []; if($modelResult->isSuccess()){ $shopResult = $modelResult->getData(); } $shopData = []; $warehouseIds = []; foreach($shopResult as $value){ if(!empty($value['warehouseId'])) { if (strpos($value['warehouseId'], ',')) { $warehouseIds = array_merge($warehouseIds, explode(',', $value['warehouseId'])); } else { $warehouseIds[] = $value['warehouseId']; } } $shopData[$value['merchantId']] = $value; } //查出仓库信息 if(!empty($merchantIds)){ $objMWarehouse = new MWarehouse($this->enterpriseId); $warehouseResult = $objMWarehouse->getNameByIds($warehouseIds); if ($warehouseResult->isSuccess()) { $warehouseData = $warehouseResult->getData(); } } foreach($data as &$value){ $value['warehouseData'] = []; $value['warehouseId'] = isset($shopData[$value['id']]) ? $shopData[$value['id']]['warehouseId'] : ''; if (!empty($value['warehouseId'])) { if(strpos($value['warehouseId'],',')){ $wid = explode(',', $value['warehouseId']); }else{ $wid = [$value['warehouseId']]; } foreach($wid as $v){ if(isset($warehouseData[$v])){ $value['warehouseData'][$v] = [ 'warehouseId' => $v, 'warehouseCode' => createCode(StatusCode::$code['warehouse']['prefix'], $v, StatusCode::$code['warehouse']['length']), 'warehouseName' => $warehouseData[$v]['warehouseName'] ]; } } } } unset($value); if(isset($params['id'])){ $return = array_shift($data); }else{ $return = $data; } return $return; } /** * 获取商户数据 * @param array $where * @return ResultWrapper */ public function getMerchantData($where = []){ $dbResult = $this->objDMerchantApply->get($where); if($dbResult === false){ return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 获取商户数据 * @param array $where * @return ResultWrapper */ public function selectMerchantData($where = []){ $dbResult = $this->objDMerchantApply->select($where); if($dbResult === false){ return ResultWrapper::fail($this->objDMerchantApply->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 保存设置 * @param $data * @param $where * @return ResultWrapper */ public function saveSetting($data, $where) { $where['enterpriseId'] = $this->enterpriseId; $setting['setting'] = json_encode($data); $setting['updateTime'] = time(); $dbResult = $this->objDMerchantSetting->get($where); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantSetting->error(), ErrorCode::$dberror); } $settingResult = $dbResult; unset($dbResult); if ($where['type'] == StatusCode::$standard) { } if (empty($settingResult)) { //新增 $setting['createTime'] = time(); $setting['enterpriseId'] = $this->enterpriseId; $setting['type'] = $where['type']; $dbResult = $this->objDMerchantSetting->insert($setting); } else { //修改 $dbResult = $this->objDMerchantSetting->update($setting, $where); } if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantSetting->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 获取设置 * @param array $where * @return ResultWrapper */ public function getSetting($where = []) { $where['enterpriseId'] = $this->enterpriseId; $dbResult = $this->objDMerchantSetting->get($where); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantSetting->error(), ErrorCode::$dberror); } if (empty($dbResult)) { return ResultWrapper::success($dbResult); } $dbResult = json_decode($dbResult['setting'], true); return ResultWrapper::success($dbResult); } /** * Doc: (des="获取配置") * User: XMing * Date: 2020/12/8 * Time: 5:41 下午 * @param $fields * @return ResultWrapper */ public function getSettingField($fields): ResultWrapper { $where['enterpriseId'] = $this->enterpriseId; $dbResult = $this->objDMerchantSetting->get($where); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantSetting->error(), ErrorCode::$dberror); } if (empty($dbResult)) { return ResultWrapper::success([]); } $dbResult = json_decode($dbResult['setting'], true); if (empty($fields)){ return ResultWrapper::success($dbResult); } if (is_string($fields)){ return ResultWrapper::success([$fields=>isset($dbResult[$fields]) ? $dbResult[$fields] : '']); } if (is_array($fields)){ $map = []; foreach ($fields as $field){ $map[$field] = isset($dbResult[$field]) ? $dbResult[$field] : ''; } return ResultWrapper::success($map); } } /** * Doc: (des="通过商铺id获取商户的信息") * User: XMing * Date: 2020/12/7 * Time: 5:25 下午 * @param int $shopId 商铺id * @return ResultWrapper */ public function getMerchByShopId(int $shopId): ResultWrapper { $fields = ' s.*, a.name as merchantName,a.balance,a.waitAuditWithdraw,a.auditWithdraw, a.withdraw,a.totalMoney,a.orderNum,a.auditOrderNum,a.finishOrderNum,a.notOrderNum,a.passOrderNum '; $sql = 'SELECT ' . $fields . ' FROM qianniao_shop_1 AS s LEFT JOIN qianniao_merchant_apply as a ON s.merchantId = a.id WHERE a.deleteStatus = ' . StatusCode::$standard . ' AND s.deleteStatus = ' . StatusCode::$standard . ' AND s.id = ' . $shopId; $shop = $this->objDShop->query($sql); if ($shop === false) { return ResultWrapper::fail($this->objDShop->error, ErrorCode::$dberror); } if (empty($shop)) { return ResultWrapper::fail('未获取到指定的商铺信息', ErrorCode::$paramError); } $shop = array_shift($shop); $shop['openTime'] = !empty($shop['openTime']) ? json_decode($shop['openTime'],true) : (object)[]; return ResultWrapper::success($shop); } /** * Doc: (des="更新商户余额") * User: XMing * Date: 2020/12/7 * Time: 6:58 下午 * @param int $id * @param array $update * @return ResultWrapper */ public function update(int $id, array $update): ResultWrapper { $dbResult = $this->objDMerchantApply->update($update, $id); if ($dbResult === false) { return ResultWrapper::fail($this->objDMerchantApply->error, ErrorCode::$dberror); } return ResultWrapper::success(true); } /** * Doc: (des="获取商户结算数据") * User: XMing * Date: 2020/12/8 * Time: 11:48 上午 * @param $id * @return ResultWrapper * @throws \Exception */ public function getWithdraw($id): ResultWrapper { if (empty($id)) { return ResultWrapper::fail('id参数错误', ErrorCode::$paramError); } $merchResult = self::getMerchByShopId($id); if (!$merchResult->isSuccess()) { return ResultWrapper::fail($merchResult->getData(), $merchResult->getErrorCode()); } $merch = $merchResult->getData(); $merchId = $merch['merchantId']; $result = $this->objDMerchantApply->get($merchId); if ($result === false) { return ResultWrapper::fail($this->objDMerchantApply->error, ErrorCode::$dberror); } $objMMerchantWithdraw = new MMerchantWithdraw($this->enterpriseId,$this->userCenterId); $takePriceResult = self::getSettingField('take_price'); if (!$takePriceResult->isSuccess()){ return ResultWrapper::fail($takePriceResult->getData(),$takePriceResult->getErrorCode()); } $takePrice = $takePriceResult->getData()['take_price']; $return = [ 'merchId' => $result['id'], 'name' => $result['name'], 'balance' => [ 'balance' => [ 'balance' => $result['balance'], 'num' => $result['orderNum'], ], 'total' => [ 'total' => $result['balance'], 'num' => 0, ], 'ret' => [ 'total' => 0, 'num' => 0, ], ], 'audit' => [ 'waitAuditWithdraw' => [ 'waitAuditWithdraw' => $result['waitAuditWithdraw'], 'num' => $result['auditOrderNum'], ],//提现等待审核 'estimate' => [ 'estimate' => $objMMerchantWithdraw->statistics(StatusCode::$auditStatus['auditing'],$id,'nowMoney'),//预计单款金额 'num' => $result['auditOrderNum'], ],//预计打款 'fee' => [ 'fee' => $objMMerchantWithdraw->statistics(StatusCode::$auditStatus['auditing'],$id,'fee'), 'rate' => $takePrice, ],//预计抽成 ], 'finish' => [ 'withdraw' => [ 'withdraw' => $result['withdraw'], 'num' => $result['finishOrderNum'] ],//总已结算金额 'not' => [ 'not' => $objMMerchantWithdraw->statistics(StatusCode::$auditStatus['auditNotPass'],$id,'money'), 'num' => $result['notOrderNum'], ],//审核未通过金额 'pass' => [ 'pass' => $objMMerchantWithdraw->statistics(StatusCode::$auditStatus['auditIng'],$id,'money'),//审核通过金额 'num' => $result['passOrderNum'] ],//审核已通过金额 'finish' => [ 'finish' => $objMMerchantWithdraw->statistics(StatusCode::$auditStatus['auditPass'],$id,'nowMoney'),//已打款金额 'fee' => $objMMerchantWithdraw->statistics(StatusCode::$auditStatus['auditPass'],$id,'fee'),//抽成 ],//已打款金额 ], ]; return ResultWrapper::success($return); } /** * Doc: (des="") * User: XMing * Date: 2020/12/30 * Time: 5:07 下午 * @return ResultWrapper */ public function statistics(): ResultWrapper { $ret = [ 'auditData' => [ 'apply' => [ 'wait' => 1, 'auditing' => 0 ], 'withdrawal' => [ 'wait' => 1, 'auditing' => 0 ], 'goods' => [ 'wait' => 1, 'auditing' => 0 ], ], 'merchant' => [ 'merch' => [ 'subNum' => 2, 'enable' => 1, 'disEnable' => 1, 'expire' => 1, ], 'goods' => [ 'num' => 1, 'inSaleNum' => 1, 'outSaleNUm' => 0, ], ], 'payData' => [ 'subPayMoney' => 10000, 'settle' => 9000, 'inSettle' => 4500, 'finishSettle' => 4500 ], 'orderData' => [ 'retOrder' => 2, 'inRetOrder' => 1, 'finishRetOrder' => 1, 'subOrder' => 3, 'waitPay' => 1, 'waitRec' => 2 ], ]; return ResultWrapper::success($ret); } /** * Doc: (des="") * User: XMing * Date: 2021/1/29 * Time: 11:51 上午 * @param int $shopId * @return ResultWrapper * @throws \Exception */ public function get(int $shopId): ResultWrapper { $shopResult = self::getMerchByShopId($shopId); if (!$shopResult->isSuccess()){ return ResultWrapper::fail($shopResult->getData(),$shopResult->getErrorCode()); } $shop = $shopResult->getData(); $objMGoods = new MGoods($this->enterpriseId,false,$this->userCenterId); $inSaleNumResult = $objMGoods->getInSaleNum($shop['id']); if (!$inSaleNumResult->isSuccess()){ return ResultWrapper::fail($inSaleNumResult->getData(),$inSaleNumResult->getErrorCode()); } $shop['inSaleGoodsNum'] = (int)$inSaleNumResult->getData(); return ResultWrapper::success($shop); } /** * 查询商户数据 * @param $merchantIds * @return array */ public function getMerchant($merchantIds) { if(!is_array($merchantIds)){ $merchantIdArray = [$merchantIds]; }else{ $merchantIdArray = $merchantIds; } $return = []; $empty = []; $objMerchantCache = new MerchantCache(); foreach($merchantIdArray as $merchantId){ $cache = $objMerchantCache->getMerchant($merchantId); if($cache){ $return[$merchantId] = $cache; }else{ $empty[] = $merchantId; } } if(!empty($empty)){ $dbResult = $this->objDMerchantApply->select(['id' => $empty]); if($dbResult !== false && !empty($dbResult)){ foreach($dbResult as $value){ $addCache = [ 'userCenterId' => $value['userCenterId'], 'name' => $value['name'], 'contactName' => $value['contactName'], 'contactMobile' => $value['contactMobile'], ]; $objMerchantCache->addMerchant($value['id'], $addCache); $return[$value['id']] = $addCache; } } } //$objMerchantCache->delMerchant(); if(!is_array($merchantIds)){ $return = array_shift($return); } return $return; } }