| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?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\stringUtil;
- use common\components\util;
- use yii\console\Controller;
- use Yii;
- class ImportCustomController extends Controller
- {
- //批量导客户进去 ssh 20230408
- public function actionInit()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $str = <<<CUSTOM
- 七天花店,17187822032
- CUSTOM;
- $str = trim($str);
- $arr = explode('
- ', $str);
- if (empty($arr) || is_array($arr) == false) {
- util::stop('客户资料有问题');
- }
- $customList = [];
- foreach ($arr as $item) {
- $item = trim($item);
- $it = explode(',', $item);
- $mobile = $it[1] ?? '';
- $name = $it[0] ?? '';
- if (empty($name)) {
- util::stop('有客户名称是空的');
- }
- if (stringUtil::isMobile($mobile) == false) {
- util::stop('有客户手机号有问题');
- }
- $customList[] = ['name' => $name, 'mobile' => $mobile];
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- if (getenv('YII_ENV') == 'production') {
- $masterShopId = 4892;
- } else {
- $masterShopId = 36523;
- }
- $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)) {
- $transaction->rollBack();
- util::stop('1');
- }
- if (stringUtil::isMobile($mobile) == false) {
- $transaction->rollBack();
- util::stop('2');
- }
- if (stringUtil::getWordNum($shopName) > 8) {
- $transaction->rollBack();
- util::stop('3');
- }
- $has = ApplyClass::getByCondition(['mobile' => $mobile]);
- if (!empty($has)) {
- $transaction->rollBack();
- util::stop('4');
- }
- $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
- if (!empty($hasShop)) {
- $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();
- }
- }
- }
|