ImportCustomController.php 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. private function actionInit()
  18. {
  19. $customList = [];
  20. $connection = Yii::$app->db;
  21. $transaction = $connection->beginTransaction();
  22. $masterShopId = 0;
  23. $master = ShopClass::getById($masterShopId, true);
  24. if (empty($master)) {
  25. util::stop('没有找到主人的门店');
  26. }
  27. if (empty($customList)) {
  28. util::stop('没有需要添加的客户');
  29. }
  30. try {
  31. foreach ($customList as $info) {
  32. $shopName = $info['name'] ?? '';
  33. $mobile = $info['mobile'] ?? 0;
  34. $post = [];
  35. $post['introSjId'] = $master->sjId ?? 0;
  36. $post['introShopId'] = $master->id ?? 0;
  37. $post['introSjName'] = $master->merchantName ?? '';
  38. $post['introStyle'] = SjClass::STYLE_SUPPLIER;
  39. $post['name'] = $shopName;
  40. $post['mobile'] = $mobile;
  41. if (empty($shopName)) {
  42. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347');
  43. $transaction->rollBack();
  44. util::stop('1');
  45. }
  46. if (stringUtil::isMobile($mobile) == false) {
  47. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347');
  48. $transaction->rollBack();
  49. util::stop('2');
  50. }
  51. if (stringUtil::getWordNum($shopName) > 8) {
  52. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了8个汉字", '15280215347');
  53. $transaction->rollBack();
  54. util::stop('3');
  55. }
  56. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  57. if (!empty($has)) {
  58. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了哦", '15280215347');
  59. $transaction->rollBack();
  60. util::stop('4');
  61. }
  62. $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
  63. if (!empty($hasShop)) {
  64. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347');
  65. $transaction->rollBack();
  66. util::stop('5');
  67. }
  68. $adminName = $post['adminName'] ?? '';
  69. $miniOpenId = $post['miniOpenId'] ?? '';
  70. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId];
  71. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  72. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  73. $adminId = $admin['id'] ?? 0;
  74. $post['adminId'] = $adminId;
  75. $post['adminName'] = $admin['name'] ?? '';
  76. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  77. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  78. $post['from'] = ApplyClass::FROM_RETAIL;
  79. $post['style'] = SjClass::STYLE_RETAIL;
  80. //增加或更新申请
  81. $respond = ApplyService::replaceRetail($post);
  82. $id = $respond['id'] ?? 0;
  83. //后继代码,要用到此参数
  84. Yii::$app->params['ptStyle'] = 2;
  85. ApplyService::pass($id, '批发商手动添加');
  86. }
  87. $transaction->commit();
  88. } catch (\Exception $exception) {
  89. $transaction->rollBack();
  90. }
  91. }
  92. }