ImportCustomController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\classes\SjClass;
  5. use bizGhs\admin\classes\AdminClass;
  6. use bizHd\saas\classes\ApplyClass;
  7. use bizHd\saas\services\ApplyService;
  8. use common\components\dict;
  9. use common\components\noticeUtil;
  10. use common\components\stringUtil;
  11. use common\components\util;
  12. use yii\console\Controller;
  13. use Yii;
  14. class ImportCustomController extends Controller
  15. {
  16. //批量导客户进去 ssh 20230408
  17. public function actionInit()
  18. {
  19. $str = <<<CUSTOM
  20. 袭人花店,18229700445
  21. 花来旺,13662131860
  22. 鲜花店,13701110216
  23. CUSTOM;
  24. $str = trim($str);
  25. $arr = explode('
  26. ', $str);
  27. if (empty($arr) || is_array($arr) == false) {
  28. util::stop('客户资料有问题');
  29. }
  30. $customList = [];
  31. foreach ($arr as $item) {
  32. $item = trim($item);
  33. $it = explode(',', $item);
  34. $mobile = $it[1] ?? '';
  35. $name = $it[0] ?? '';
  36. if (empty($name)) {
  37. util::stop('有客户名称是空的');
  38. }
  39. if (stringUtil::isMobile($mobile) == false) {
  40. util::stop('有客户手机号有问题');
  41. }
  42. $customList[] = ['name' => $name, 'mobile' => $mobile];
  43. }
  44. $connection = Yii::$app->db;
  45. $transaction = $connection->beginTransaction();
  46. if (getenv('YII_ENV') == 'production') {
  47. $masterShopId = 4892;
  48. } else {
  49. $masterShopId = 36523;
  50. }
  51. $master = ShopClass::getById($masterShopId, true);
  52. if (empty($master)) {
  53. util::stop('没有找到主人的门店');
  54. }
  55. if (empty($customList)) {
  56. util::stop('没有需要添加的客户');
  57. }
  58. try {
  59. foreach ($customList as $info) {
  60. $shopName = $info['name'] ?? '';
  61. $mobile = $info['mobile'] ?? 0;
  62. $post = [];
  63. $post['introSjId'] = $master->sjId ?? 0;
  64. $post['introShopId'] = $master->id ?? 0;
  65. $post['introSjName'] = $master->merchantName ?? '';
  66. $post['introStyle'] = SjClass::STYLE_SUPPLIER;
  67. $post['name'] = $shopName;
  68. $post['mobile'] = $mobile;
  69. if (empty($shopName)) {
  70. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347');
  71. $transaction->rollBack();
  72. util::stop('1');
  73. }
  74. if (stringUtil::isMobile($mobile) == false) {
  75. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347');
  76. $transaction->rollBack();
  77. util::stop('2');
  78. }
  79. if (stringUtil::getWordNum($shopName) > 8) {
  80. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了8个汉字", '15280215347');
  81. $transaction->rollBack();
  82. util::stop('3');
  83. }
  84. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  85. if (!empty($has)) {
  86. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了哦", '15280215347');
  87. $transaction->rollBack();
  88. util::stop('4');
  89. }
  90. $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
  91. if (!empty($hasShop)) {
  92. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347');
  93. $transaction->rollBack();
  94. util::stop('5');
  95. }
  96. $adminName = $post['adminName'] ?? '';
  97. $miniOpenId = $post['miniOpenId'] ?? '';
  98. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId];
  99. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  100. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  101. $adminId = $admin['id'] ?? 0;
  102. $post['adminId'] = $adminId;
  103. $post['adminName'] = $admin['name'] ?? '';
  104. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  105. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  106. $post['from'] = ApplyClass::FROM_RETAIL;
  107. $post['style'] = SjClass::STYLE_RETAIL;
  108. //增加或更新申请
  109. $respond = ApplyService::replaceRetail($post);
  110. $id = $respond['id'] ?? 0;
  111. //后继代码,要用到此参数
  112. Yii::$app->params['ptStyle'] = 2;
  113. ApplyService::pass($id, '批发商手动添加');
  114. }
  115. $transaction->commit();
  116. } catch (\Exception $exception) {
  117. $transaction->rollBack();
  118. }
  119. }
  120. }