| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace console\controllers;
- use biz\shop\classes\ShopClass;
- use biz\sj\classes\SjClass;
- use bizGhs\admin\classes\AdminClass;
- use bizHd\saas\classes\ApplyClass;
- use bizHd\saas\services\ApplyService;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\stringUtil;
- use common\components\util;
- use yii\console\Controller;
- use Yii;
- class ImportCustomController extends Controller
- {
- //批量导客户进去 ssh 20230408
- private function actionInit()
- {
- $customList = [];
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- $masterShopId = 0;
- $master = ShopClass::getById($masterShopId, true);
- if (empty($master)) {
- util::stop('没有找到主人的门店');
- }
- if (empty($customList)) {
- util::stop('没有需要添加的客户');
- }
- try {
- foreach ($customList as $info) {
- $shopName = $info['name'] ?? '';
- $mobile = $info['mobile'] ?? 0;
- $post = [];
- $post['introSjId'] = $master->sjId ?? 0;
- $post['introShopId'] = $master->id ?? 0;
- $post['introSjName'] = $master->merchantName ?? '';
- $post['introStyle'] = SjClass::STYLE_SUPPLIER;
- $post['name'] = $shopName;
- $post['mobile'] = $mobile;
- if (empty($shopName)) {
- noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347');
- $transaction->rollBack();
- util::stop('1');
- }
- if (stringUtil::isMobile($mobile) == false) {
- noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347');
- $transaction->rollBack();
- util::stop('2');
- }
- if (stringUtil::getWordNum($shopName) > 8) {
- noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了8个汉字", '15280215347');
- $transaction->rollBack();
- util::stop('3');
- }
- $has = ApplyClass::getByCondition(['mobile' => $mobile]);
- if (!empty($has)) {
- noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了哦", '15280215347');
- $transaction->rollBack();
- util::stop('4');
- }
- $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
- if (!empty($hasShop)) {
- noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347');
- $transaction->rollBack();
- util::stop('5');
- }
- $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'] : '';
- $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
- $post['from'] = ApplyClass::FROM_RETAIL;
- $post['style'] = SjClass::STYLE_RETAIL;
- //增加或更新申请
- $respond = ApplyService::replaceRetail($post);
- $id = $respond['id'] ?? 0;
- //后继代码,要用到此参数
- Yii::$app->params['ptStyle'] = 2;
- ApplyService::pass($id, '批发商手动添加');
- }
- $transaction->commit();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- }
- }
- }
|