|
|
@@ -137,23 +137,26 @@ class CustomController extends Controller
|
|
|
|
|
|
public function actionCreateCustomer()
|
|
|
{
|
|
|
+ //批量创建客户
|
|
|
$this->createCustomer();
|
|
|
+ //从首店同步客户
|
|
|
$this->copyCustomers();
|
|
|
}
|
|
|
|
|
|
+ //批量创建客户
|
|
|
private function createCustomer()
|
|
|
{
|
|
|
- $customerCachedKey = 'customers_list';
|
|
|
+ $customerCachedKey = 'batch_create_customer_list';
|
|
|
+ $customList = [];
|
|
|
while ($count = Yii::$app->redis->executeCommand('LLEN', [$customerCachedKey])) {
|
|
|
$customer = Yii::$app->redis->executeCommand('RPOP', [$customerCachedKey]);
|
|
|
- $customers[] = $customer;
|
|
|
+ $customList[] = $customer;
|
|
|
}
|
|
|
-
|
|
|
- if (!isset($customers)) {
|
|
|
- return;
|
|
|
+ if (empty($customList)) {
|
|
|
+ return false;
|
|
|
}
|
|
|
+ foreach ($customList as $customer) {
|
|
|
|
|
|
- foreach($customers as $customer) {
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
|
|
|
@@ -161,105 +164,79 @@ class CustomController extends Controller
|
|
|
$shopName = $customerInfo[0];
|
|
|
$mobile = $customerInfo[1];
|
|
|
|
|
|
- $post = []; // 组织表单数据
|
|
|
- $post['introSjId'] = $customerInfo[2];
|
|
|
- $post['introShopId'] = $customerInfo[3];
|
|
|
- $post['introSjName'] = $customerInfo[4];
|
|
|
- //$post['ghsShopAdminId'] = $customerInfo[5]; // 取供应商的员工帐号id
|
|
|
- $post['name'] = $shopName;
|
|
|
- $post['mobile'] = $mobile;
|
|
|
-
|
|
|
- if (empty($shopName)) {
|
|
|
- Yii::info('名称不能为空');
|
|
|
- continue;
|
|
|
- }
|
|
|
+ try {
|
|
|
|
|
|
- if (stringUtil::isMobile($mobile) == false) {
|
|
|
- Yii::info('请填写正确手机号');
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (stringUtil::getWordNum($shopName) > 8) {
|
|
|
- Yii::info('名称不能超过8个汉字');
|
|
|
- continue;
|
|
|
- }
|
|
|
- $has = SjClass::getByCondition(['name' => $shopName]);
|
|
|
- if (!empty($has)) {
|
|
|
- Yii::info('名称已经存在');
|
|
|
- continue;
|
|
|
- }
|
|
|
- $has = ApplyClass::getByCondition(['mobile' => $mobile]);
|
|
|
- if (!empty($has)) {
|
|
|
- //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
|
|
|
- Yii::info('手机号已经申请过了(手机号开了零售店)');
|
|
|
- continue;
|
|
|
- }
|
|
|
- $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
|
|
|
- if (!empty($hasShop)) {
|
|
|
- //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
|
|
|
- Yii::info('手机号已经被使用(手机号开了零售店)');
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $post = [];// 组织表单数据
|
|
|
+ $post['introSjId'] = $customerInfo[2];
|
|
|
+ $post['introShopId'] = $customerInfo[3];
|
|
|
+ $post['introSjName'] = $customerInfo[4];
|
|
|
|
|
|
- $adminName = $post['adminName'] ?? '';
|
|
|
- $miniOpenId = $post['miniOpenId'] ?? '';
|
|
|
- $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId];
|
|
|
- $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
|
|
|
+ $post['name'] = $shopName;
|
|
|
+ if (empty($shopName)) {
|
|
|
+ noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:名称没有填写", '15280215347');
|
|
|
+ $transaction->rollBack();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
|
|
|
- $adminId = $admin['id'] ?? 0;
|
|
|
- $currentShopId = $admin['currentShopId'] ?? 0;
|
|
|
- if (!empty($currentShopId)) {
|
|
|
- util::fail('您已提交过申请,管理员ID:' . $adminId);
|
|
|
- }
|
|
|
- if (isset($admin['openShop']) && $admin['openShop'] == 2) {
|
|
|
- util::fail('审核中,无需重复申请');
|
|
|
- }
|
|
|
- $post['adminId'] = $adminId;
|
|
|
- $post['adminName'] = $admin['name'] ?? '';
|
|
|
- $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';// TODO
|
|
|
- $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';// TODO
|
|
|
- $post['from'] = ApplyClass::FROM_RETAIL;
|
|
|
- $post['style'] = SjClass::STYLE_RETAIL; //零售店
|
|
|
- $post['introStyle'] = SjClass::STYLE_SUPPLIER; //
|
|
|
-
|
|
|
- //增加或更新申请
|
|
|
- $respond = ApplyService::replaceRetail($post);
|
|
|
- $id = $respond['id'] ?? 0;
|
|
|
- if (empty($id)) {
|
|
|
- Yii::info('申请失败');
|
|
|
- continue;
|
|
|
- }
|
|
|
- Yii::$app->params['ptStyle'] = 2; // 后继代码,要用到此参数
|
|
|
- $passInfo = ApplyService::pass($id, '批发商手动创建客户,脚本执行创建,并自动审核');
|
|
|
-
|
|
|
- //输出登录信息
|
|
|
- $newShop = $passInfo['shop'] ?? [];
|
|
|
- $newMainId = $newShop->mainId ?? 0;
|
|
|
- $newShopId = $newShop->id ?? 0;
|
|
|
-
|
|
|
- //前端用于判断是否注册
|
|
|
- $admin['currentShopId'] = $newShopId;
|
|
|
- $adminId = $admin['id'];
|
|
|
- $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true);
|
|
|
- if (empty($shopAdmin)) {
|
|
|
- Yii::info('没有找到管理员');
|
|
|
- continue;
|
|
|
- }
|
|
|
- //$shopAdmin->lastLogin = date("Y-m-d H:i:s");
|
|
|
- //$shopAdmin->save();
|
|
|
+ $post['mobile'] = $mobile;
|
|
|
+ if (stringUtil::isMobile($mobile) == false) {
|
|
|
+ noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:手机号填写错误", '15280215347');
|
|
|
+ $transaction->rollBack();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (stringUtil::getWordNum($shopName) > 8) {
|
|
|
+ noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:名称超过了8个汉字", '15280215347');
|
|
|
+ $transaction->rollBack();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $has = SjClass::getByCondition(['name' => $shopName]);
|
|
|
+ if (!empty($has)) {
|
|
|
+ noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:名称已经存在了哦", '15280215347');
|
|
|
+ $transaction->rollBack();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $has = ApplyClass::getByCondition(['mobile' => $mobile]);
|
|
|
+ if (!empty($has)) {
|
|
|
+ noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:手机号已经存在了哦", '15280215347');
|
|
|
+ $transaction->rollBack();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
|
|
|
+ if (!empty($hasShop)) {
|
|
|
+ noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:手机号已经存在了", '15280215347');
|
|
|
+ $transaction->rollBack();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
|
|
|
- if ($hdUpgrading == 1) {
|
|
|
- Yii::info('系统升级中,稍后再试');
|
|
|
- continue;
|
|
|
+ $adminName = $post['adminName'] ?? '';
|
|
|
+ $miniOpenId = $post['miniOpenId'] ?? '';
|
|
|
+ $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId];
|
|
|
+ $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
|
|
|
+
|
|
|
+ $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
|
|
|
+ $adminId = $admin['id'] ?? 0;
|
|
|
+ $post['adminId'] = $adminId;
|
|
|
+ $post['adminName'] = $admin['name'] ?? '';
|
|
|
+ $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';// TODO
|
|
|
+ $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';// TODO
|
|
|
+ $post['from'] = ApplyClass::FROM_RETAIL;
|
|
|
+ $post['style'] = SjClass::STYLE_RETAIL;
|
|
|
+
|
|
|
+ //增加或更新申请
|
|
|
+ $respond = ApplyService::replaceRetail($post);
|
|
|
+ $id = $respond['id'] ?? 0;
|
|
|
+ ApplyService::pass($id, '批发商手动添加');
|
|
|
+ $transaction->commit();
|
|
|
+
|
|
|
+ noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商手动添加", '15280215347');
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:" . $exception->getMessage(), '15280215347');
|
|
|
}
|
|
|
- $transaction->commit();
|
|
|
- noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 被批发商手动注册", '15280215347');
|
|
|
-
|
|
|
- echo "create customers success";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //从首店同步客户
|
|
|
private function copyCustomers()
|
|
|
{
|
|
|
$cachedKey = 'copy_firstShop_customers';
|
|
|
@@ -272,7 +249,7 @@ class CustomController extends Controller
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- foreach($shopIdDatas as $shopIdData) {
|
|
|
+ foreach ($shopIdDatas as $shopIdData) {
|
|
|
$shopIdArr = explode('_', $shopIdData);
|
|
|
if (count($shopIdArr) != 2) {
|
|
|
Yii::info('copyCustomers 数据出错:' . json_encode($shopIdArr));
|
|
|
@@ -284,8 +261,8 @@ class CustomController extends Controller
|
|
|
|
|
|
Yii::$app->params['ptStyle'] = 2; // 后继代码,要用到此参数
|
|
|
$customers = CustomClass::getAllByCondition(['ownShopId' => $defaultShopId], null, ['shopId']);
|
|
|
- foreach($customers as $customer) {
|
|
|
- $exist = CustomClass::exists(['ownShopId'=> $shopId, 'shopId'=>$customer['shopId']]);
|
|
|
+ foreach ($customers as $customer) {
|
|
|
+ $exist = CustomClass::exists(['ownShopId' => $shopId, 'shopId' => $customer['shopId']]);
|
|
|
if (!$exist) {
|
|
|
CustomClass::build($shopId, $customer['shopId']);
|
|
|
}
|