ItemController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <?php
  2. namespace console\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\item\classes\PtItemClass;
  5. use biz\item\classes\PtItemClassClass;
  6. use biz\sj\classes\SjClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use biz\shop\classes\ShopClass;
  9. use bizGhs\item\classes\ItemClass;
  10. use bizGhs\item\classes\ItemClassClass;
  11. use bizGhs\order\classes\StockWastageOrderClass;
  12. use bizGhs\order\classes\StockWastageOrderItemClass;
  13. use bizHd\saas\classes\ApplyClass;
  14. use bizHd\saas\models\Apply;
  15. use bizHd\saas\services\ApplyService;
  16. use common\components\dict;
  17. use common\components\imgUtil;
  18. use common\components\stringUtil;
  19. use yii\console\Controller;
  20. use Yii;
  21. use bizGhs\product\classes\ProductClass;
  22. /**
  23. * 花材初始化 ssh 2021.2.18
  24. */
  25. class ItemController extends Controller
  26. {
  27. public $sjId, $shopId, $sj;
  28. public function actionWaste()
  29. {
  30. ini_set('memory_limit', '2045M');
  31. set_time_limit(0);
  32. $list = StockWastageOrderClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  33. if (!empty($list)) {
  34. foreach ($list as $order) {
  35. $orderSn = $order->orderSn ?? '';
  36. $itemList = StockWastageOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  37. $totalCost = 0;
  38. if (!empty($itemList)) {
  39. foreach ($itemList as $v) {
  40. $num = $v->itemNum ?? 0;
  41. $itemCost = $v->itemCost ?? 0;
  42. $totalCost = bcadd($totalCost, bcmul($num, $itemCost, 2), 2);
  43. }
  44. }
  45. $order->cost = $totalCost;
  46. $order->save();
  47. }
  48. }
  49. }
  50. public function actionWastage()
  51. {
  52. ini_set('memory_limit', '2045M');
  53. set_time_limit(0);
  54. $list = StockWastageOrderClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  55. if (!empty($list)) {
  56. foreach ($list as $order) {
  57. $orderSn = $order->orderSn ?? '';
  58. $itemList = StockWastageOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  59. $totalPrice = 0;
  60. if (!empty($itemList)) {
  61. foreach ($itemList as $v) {
  62. $num = $v->itemNum ?? 0;
  63. $itemPrice = $v->itemPrice ?? 0;
  64. $totalPrice = bcadd($totalPrice, bcmul($num, $itemPrice, 2), 2);
  65. }
  66. }
  67. $order->price = $totalPrice;
  68. $order->save();
  69. }
  70. }
  71. }
  72. //初见花季 ssh 20230223
  73. public function actionCj()
  74. {
  75. if (getenv('YII_ENV') == 'production') {
  76. $mtMainId = 0;
  77. $ttMainId = 53;
  78. } else {
  79. $mtMainId = 703;
  80. $ttMainId = 644;
  81. }
  82. $list = ItemClass::getAllByCondition(['mainId' => $mtMainId], null, '*');
  83. if (!empty($list)) {
  84. echo '已经有花材了';
  85. exit();
  86. }
  87. $classList = ItemClassClass::getAllByCondition(['mainId' => $ttMainId], null, '*', null, true);
  88. if (empty($classList)) {
  89. echo '没有找到天天鲜花的分类';
  90. exit();
  91. }
  92. $connection = Yii::$app->db;
  93. $transaction = $connection->beginTransaction();
  94. try {
  95. foreach ($classList as $class) {
  96. $oldId = $class->id ?? 0;
  97. $cover = $class->cover ?? '';
  98. $name = $class->name ?? '';
  99. $inTurn = $class->inTurn ?? 0;
  100. $isDefault = $class->isDefault ?? 0;
  101. $newClass = [
  102. 'mainId' => $mtMainId,
  103. 'cover' => $cover,
  104. 'name' => $name,
  105. 'inTurn' => $inTurn,
  106. 'isDefault' => $isDefault,
  107. ];
  108. $newRespond = ItemClassClass::add($newClass, true);
  109. $newClassId = $newRespond->id ?? 0;
  110. $oldItemList = ItemClass::getAllByCondition(['classId' => $oldId, 'delStatus' => 0], null, '*');
  111. foreach ($oldItemList as $oldItem) {
  112. unset($oldItem['id']);
  113. $oldItem['classId'] = $newClassId;
  114. $oldItem['stock'] = 0;
  115. $oldItem['status'] = 2;
  116. $oldItem['mainId'] = $mtMainId;
  117. $oldItem['sjId'] = 16300;
  118. $oldItem['shopId'] = 0;
  119. ItemClass::add($oldItem);
  120. }
  121. }
  122. $transaction->commit();
  123. } catch (\Exception $e) {
  124. $transaction->rollBack();
  125. $msg = $e->getMessage();
  126. echo "报错了:" . $msg;
  127. }
  128. }
  129. public function actionMt()
  130. {
  131. if (getenv('YII_ENV') == 'production') {
  132. $mtMainId = 3923;
  133. $ttMainId = 742;
  134. } else {
  135. $mtMainId = 703;
  136. $ttMainId = 644;
  137. }
  138. $list = ItemClass::getAllByCondition(['mainId' => $mtMainId], null, '*');
  139. if (!empty($list)) {
  140. echo '已经有花材了';
  141. exit();
  142. }
  143. $classList = ItemClassClass::getAllByCondition(['mainId' => $ttMainId], null, '*', null, true);
  144. if (empty($classList)) {
  145. echo '没有找到天天鲜花的分类';
  146. exit();
  147. }
  148. $connection = Yii::$app->db;
  149. $transaction = $connection->beginTransaction();
  150. try {
  151. foreach ($classList as $class) {
  152. $oldId = $class->id ?? 0;
  153. $cover = $class->cover ?? '';
  154. $name = $class->name ?? '';
  155. $inTurn = $class->inTurn ?? 0;
  156. $isDefault = $class->isDefault ?? 0;
  157. $newClass = [
  158. 'mainId' => $mtMainId,
  159. 'cover' => $cover,
  160. 'name' => $name,
  161. 'inTurn' => $inTurn,
  162. 'isDefault' => $isDefault,
  163. ];
  164. $newRespond = ItemClassClass::add($newClass, true);
  165. $newClassId = $newRespond->id ?? 0;
  166. $oldItemList = ItemClass::getAllByCondition(['classId' => $oldId, 'delStatus' => 0], null, '*');
  167. foreach ($oldItemList as $oldItem) {
  168. unset($oldItem['id']);
  169. $oldItem['classId'] = $newClassId;
  170. $oldItem['stock'] = 0;
  171. $oldItem['status'] = 2;
  172. $oldItem['mainId'] = $mtMainId;
  173. $oldItem['sjId'] = 16300;
  174. $oldItem['shopId'] = 0;
  175. ItemClass::add($oldItem);
  176. }
  177. }
  178. $transaction->commit();
  179. } catch (\Exception $e) {
  180. $transaction->rollBack();
  181. $msg = $e->getMessage();
  182. echo "报错了:" . $msg;
  183. }
  184. }
  185. //花材反向更新 ./yii item/reverse-update
  186. public function actionReverseUpdate()
  187. {
  188. $shopId = 10;
  189. if (getenv('YII_ENV') != 'production') {
  190. $shopId = 36225;
  191. }
  192. $list = ProductClass::getAllByCondition(['shopId' => $shopId], null, '*', null, true);
  193. if (empty($list)) {
  194. return false;
  195. }
  196. foreach ($list as $cKey => $product) {
  197. $ptItemId = $product->itemId ?? 0;
  198. $ptItem = PtItemClass::getById($ptItemId, true);
  199. if (empty($ptItem)) {
  200. continue;
  201. }
  202. $ptItem->name = $product->name ?? '';
  203. $ptItem->py = $product->py ?? '';
  204. $ptItem->cover = $product->cover ?? '';
  205. $ptItem->ratio = $product->ratio ?? 1;
  206. $ptItem->shelfLife = $product->shelfLife ?? 7;
  207. $ptItem->weight = $product->weight ?? 0.1;
  208. $ptItem->stockWarning = $product->stockWarning ?? 5;;
  209. $ptItem->cost = $product->cost ?? 1;
  210. $ptItem->addPrice = 5;
  211. $ptItem->bigUnit = $product->bigUnit;
  212. $ptItem->smallUnit = $product->smallUnit;
  213. $ptItem->bigUnitId = $product->bigUnitId;
  214. $ptItem->smallUnitId = $product->smallUnitId;
  215. $ptItem->save();
  216. echo $product->id . " " . $product->name . " 已同步\n";
  217. }
  218. }
  219. //命令: ./yii item/sync name,cover 同步name 和cover
  220. //同步item, ptItem更新,同步到 ghsItem, ghsProduct, 同步字段(name,alias,py,cover,ratio,cover等)
  221. public function actionSync($field)
  222. {
  223. $allFiled = ['name', 'alias', 'cover', 'py', 'ratio', 'weight', 'bigUnit', 'smallUnit', 'bigUnitId', 'smallUnitId', 'stockWarning'];
  224. $fields = explode(",", $field);
  225. $syncFields = array_intersect($allFiled, $fields);
  226. if (empty($syncFields)) {
  227. echo "参数不支持";
  228. die;
  229. }
  230. $item = PtItemClass::getAllList("id", "");
  231. $itemIds = [];
  232. foreach ($item as $v) {
  233. $itemIds[] = $v['id'];
  234. }
  235. if (!empty($itemIds)) {
  236. foreach ($itemIds as $v) {
  237. $itemInfo = PtItemClass::getById($v);
  238. $data = [];
  239. foreach ($syncFields as $f) {
  240. $data[$f] = $itemInfo[$f];
  241. }
  242. ProductClass::updateByCondition(['itemId' => $v], $data);
  243. \bizGhs\item\classes\ItemClass::updateByCondition(['itemId' => $v], $data);
  244. }
  245. }
  246. echo "done";
  247. }
  248. //平台花材初始化导入 lqh 2021-05-08
  249. //命令: ./yii item/init-pt-item
  250. public function actionInitPtItem($clear = false)
  251. {
  252. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  253. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');//查询接口
  254. $dir = Yii::$app->basePath;
  255. $filename = $dir . '/item.xls';
  256. $fileType = \PHPExcel_IOFactory::identify($filename); //文件名自动判断文件类型
  257. $excelReader = \PHPExcel_IOFactory::createReader($fileType);
  258. $objPHPExcel = $excelReader->load($filename);//$file_url即Excel文件的路径
  259. $sheet = $objPHPExcel->getSheet(0);//获取第一个工作表
  260. $highestRow = $sheet->getHighestRow();//取得总行数
  261. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  262. $classData = [];
  263. $itemData = [];
  264. $classIdMap = [];
  265. for ($j = 2; $j <= $highestRow; $j++) {
  266. $str = '';
  267. for ($k = 'A'; $k <= $highestColumn; $k++) {
  268. $str .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue() . '\\';
  269. }
  270. //explode:函数把字符串分割为数组。
  271. $string = explode("\\", $str);
  272. array_pop($string);
  273. $itemName = $string[0] ?? ''; //花材名称
  274. $className = $string[1] ?? ''; //分类名称
  275. $weight = $string[2] ?? 0; //重量 kg
  276. $bigUnit = $string[3] ?? ''; //大单位名称
  277. $smallUnit = $string[4] ?? ''; //小单位名称
  278. $ratio = $string[5] ?? 0; //比例
  279. $cost = $string[6] ?? 0;//成本价
  280. $addPrice = $string[7] ?? 0; //加价
  281. $stockWarning = $string[8] ?? 0;
  282. $alias = $string[9] ?? '';
  283. $cover = $string[10] ?? '';
  284. $inTurn = $string[11] ?? 0;
  285. if ($itemName) {
  286. $py = stringUtil::py($itemName);
  287. $item = [
  288. 'name' => $itemName,
  289. 'alias' => $alias,
  290. 'py' => $py,
  291. 'cover' => $cover,
  292. 'classId' => 0,
  293. 'ratio' => $ratio,
  294. 'weight' => $weight,
  295. 'stockWarning' => $stockWarning,
  296. 'cost' => $cost,
  297. 'addPrice' => $addPrice,
  298. 'bigUnit' => $bigUnit,
  299. 'smallUnit' => $smallUnit,
  300. 'inTurn' => $inTurn,
  301. ];
  302. $itemData[$className][] = $item;
  303. $classData[] = $className;
  304. }
  305. }
  306. $classData = array_unique($classData);
  307. //写入class
  308. if ($clear) {
  309. //清空数据
  310. Yii::$app->db->createCommand()->truncateTable('xhPtItemClass')->execute();
  311. Yii::$app->db->createCommand()->truncateTable('xhPtItem')->execute();
  312. }
  313. foreach ($classData as $v) {
  314. $addClass = PtItemClassClass::add(['name' => $v, 'inTurn' => 0, 'group' => 0]);
  315. $classIdMap[$v] = $addClass['id'];
  316. }
  317. $insertItemData = [];
  318. foreach ($itemData as $k => $v) {
  319. $classId = $classIdMap[$k] ?? 0;
  320. if ($classId) {
  321. foreach ($v as $i) {
  322. $i['classId'] = $classId;
  323. $insertItemData[] = $i;
  324. }
  325. }
  326. }
  327. if (!empty($insertItemData)) {
  328. PtItemClass::batchAdd($insertItemData);
  329. }
  330. echo "done";
  331. }
  332. //供货商初始化 ./yii item/gys ./yii.bat item/gys
  333. public function actionGys()
  334. {
  335. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  336. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');//查询接口
  337. $dir = Yii::$app->basePath;
  338. $filename = $dir . '/gys.xls';
  339. $fileType = \PHPExcel_IOFactory::identify($filename); //文件名自动判断文件类型
  340. $excelReader = \PHPExcel_IOFactory::createReader($fileType);
  341. $objPHPExcel = $excelReader->load($filename);//$file_url即Excel文件的路径
  342. $sheet = $objPHPExcel->getSheet(0);//获取第一个工作表
  343. $highestRow = $sheet->getHighestRow();//取得总行数
  344. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  345. $changeData = [];
  346. for ($j = 2; $j <= $highestRow; $j++) {
  347. $str = '';
  348. for ($k = 'A'; $k <= $highestColumn; $k++) {
  349. $str .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue() . '\\';
  350. }
  351. //explode:函数把字符串分割为数组。
  352. $string = explode("\\", $str);
  353. array_pop($string);
  354. array_push($changeData, $string);
  355. }
  356. if (!empty($changeData)) {
  357. $mobileList = array_values(array_column($changeData, 1));
  358. $ptStyle = dict::getDict('ptStyle', 'kmGhs');
  359. Yii::$app->params['ptStyle'] = $ptStyle;
  360. $has = Apply::find()->where(['in', 'mobile', $mobileList])->andWhere(['style' => $ptStyle])->all();
  361. if (!empty($has)) {
  362. echo "这些已经添加过了,请先删除:\n";
  363. foreach ($has as $item) {
  364. echo $item->name . ' ' . $item->mobile . "\n";
  365. }
  366. exit();
  367. }
  368. if (getenv('YII_ENV') == 'production') {
  369. $this->sjId = 12367;
  370. $this->shopId = 10;
  371. } else {
  372. $this->sjId = 12615;
  373. $this->shopId = 36119;
  374. }
  375. foreach ($changeData as $currentKey => $currentData) {
  376. $mobile = $currentData[1] ?? '';
  377. $name = $currentData[0] ?? '';
  378. $address = $currentData[2] ?? '';
  379. if (stringUtil::isMobile($mobile) == false) {
  380. echo "请填写正确的手机号 \n";
  381. continue;
  382. }
  383. if (empty($name)) {
  384. echo "{$mobile} 名称不能为空 \n";
  385. continue;
  386. }
  387. if (stringUtil::getWordNum($name) > 8) {
  388. echo "{$mobile} 名称不能超过8个汉字 \n";
  389. continue;
  390. }
  391. $has = ApplyClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  392. if (!empty($has)) {
  393. echo "{$mobile} 名称已经存在 \n";
  394. continue;
  395. }
  396. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  397. if (!empty($has)) {
  398. echo "{$mobile} 手机号已经添加过 \n";
  399. continue;
  400. }
  401. $connection = Yii::$app->db;
  402. $transaction = $connection->beginTransaction();
  403. try {
  404. $sjId = $this->sjId;
  405. $shopId = $this->shopId;
  406. $sjName = $this->sj->name ?? '';
  407. $applyData = [
  408. 'name' => $name,
  409. 'licenseNo' => $mobile,
  410. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  411. 'mobile' => $mobile,
  412. 'introSjId' => $sjId,
  413. 'introSjName' => $sjName,
  414. 'introShopId' => $shopId,
  415. 'introStyle' => SjClass::STYLE_SUPPLIER,
  416. 'from' => ApplyClass::FROM_GHS,
  417. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  418. 'address' => $address,
  419. 'status' => ApplyClass::STATUS_PASS,
  420. 'replace' => 1,//1表示供货商添加的客户或供货商
  421. ];
  422. $apply = ApplyService::replaceKmGhs($applyData);
  423. $id = $apply['id'] ?? 0;
  424. $respond = ApplyService::pass($id);
  425. $currentShop = $respond['shop'] ?? [];
  426. $sj = $respond['sj'] ?? [];
  427. $currentSjId = $sj['id'] ?? 0;
  428. $currentShopId = $currentShop->id ?? 0;
  429. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  430. if (empty($currentShopId)) {
  431. echo "{$mobile} 供货商添加失败 \n ";
  432. continue;
  433. }
  434. GhsClass::build($currentShopId, $shopId, 1);
  435. $transaction->commit();
  436. echo "{$mobile} 供货商添加成功!\n";
  437. } catch (\Exception $exception) {
  438. $transaction->rollBack();
  439. echo "{$mobile} 供货商添加失败,原因:" . $exception->getMessage() . "\n";
  440. }
  441. }
  442. }
  443. }
  444. //客户初始化 ./yii item/custom ./yii.bat item/custom
  445. public function actionCustom()
  446. {
  447. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  448. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');//查询接口
  449. $dir = Yii::$app->basePath;
  450. $filename = $dir . '/custom.xls';
  451. $fileType = \PHPExcel_IOFactory::identify($filename); //文件名自动判断文件类型
  452. $excelReader = \PHPExcel_IOFactory::createReader($fileType);
  453. $objPHPExcel = $excelReader->load($filename);//$file_url即Excel文件的路径
  454. $sheet = $objPHPExcel->getSheet(0);//获取第一个工作表
  455. $highestRow = $sheet->getHighestRow();//取得总行数
  456. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  457. $changeData = [];
  458. for ($j = 2; $j <= $highestRow; $j++) {
  459. $str = '';
  460. for ($k = 'A'; $k <= $highestColumn; $k++) {
  461. $str .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue() . '\\';
  462. }
  463. //explode:函数把字符串分割为数组。
  464. $string = explode("\\", $str);
  465. array_pop($string);
  466. array_push($changeData, $string);
  467. }
  468. if (!empty($changeData)) {
  469. $mobileList = array_values(array_column($changeData, 1));
  470. $ptStyle = dict::getDict('ptStyle', 'hd');
  471. Yii::$app->params['ptStyle'] = $ptStyle;
  472. $has = Apply::find()->where(['in', 'mobile', $mobileList])->andWhere(['style' => $ptStyle])->all();
  473. if (!empty($has)) {
  474. echo "这些已经添加过了,请先删除:\n";
  475. foreach ($has as $item) {
  476. echo $item->name . ' ' . $item->mobile . "\n";
  477. }
  478. exit();
  479. }
  480. if (getenv('YII_ENV') == 'production') {
  481. $this->sjId = 12367;
  482. $this->shopId = 10;
  483. } else {
  484. $this->sjId = 12615;
  485. $this->shopId = 36119;
  486. }
  487. $shop = ShopClass::getById($this->shopId, true);
  488. $sj = SjClass::getById($this->sjId, true);
  489. $this->sj = $sj;
  490. foreach ($changeData as $currentKey => $currentData) {
  491. $mobile = $currentData[1] ?? '';
  492. $name = $currentData[0] ?? '';
  493. $address = $currentData[2] ?? '';
  494. if (empty($name)) {
  495. echo "{$mobile} 名称不能为空 \n";
  496. continue;
  497. }
  498. if (stringUtil::getWordNum($name) > 8) {
  499. echo "{$mobile} 名称不能超过8个汉字 \n";
  500. continue;
  501. }
  502. if (stringUtil::isMobile($mobile) == false) {
  503. echo "{$mobile} 手机号错误 \n";
  504. continue;
  505. }
  506. $has = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]);
  507. if (!empty($has)) {
  508. echo "{$mobile} 名称已经存在 \n";
  509. continue;
  510. }
  511. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]);
  512. if (!empty($has)) {
  513. echo "{$mobile} 手机号已经添加过 \n";
  514. continue;
  515. }
  516. $connection = Yii::$app->db;
  517. $transaction = $connection->beginTransaction();
  518. try {
  519. $sjId = $this->sjId;
  520. $shopId = $this->shopId;
  521. $sjName = $this->sj->name ?? '';
  522. $city = $shop->city ?? '';
  523. $dist = $shop->dist ?? '';
  524. $applyData = [
  525. 'name' => $name,
  526. 'licenseNo' => $mobile,
  527. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  528. 'mobile' => $mobile,
  529. 'introSjId' => $sjId,
  530. 'introSjName' => $sjName,
  531. 'introShopId' => $shopId,
  532. 'introStyle' => SjClass::STYLE_SUPPLIER,
  533. 'from' => ApplyClass::FROM_GHS,
  534. 'style' => SjClass::STYLE_RETAIL,
  535. 'province' => $shop->province ?? '',
  536. 'city' => $city,
  537. 'dist' => $dist,
  538. 'address' => $address,
  539. 'status' => ApplyClass::STATUS_PASS,
  540. 'replace' => 1,//1表示供货商添加的客户
  541. ];
  542. $apply = ApplyService::replaceRetail($applyData);
  543. $id = $apply['id'] ?? 0;
  544. $respond = ApplyService::pass($id);
  545. $currentShop = $respond['shop'] ?? [];
  546. $sj = $respond['sj'] ?? [];
  547. $hdSjId = $sj['id'] ?? 0;
  548. $hdShopId = $currentShop->id ?? 0;
  549. ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
  550. if (empty($hdShopId)) {
  551. echo "{$mobile} 客户添加失败 \n";
  552. continue;
  553. }
  554. $custom = CustomClass::build($this->shopId, $hdShopId);
  555. $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
  556. $transaction->commit();
  557. echo "{$mobile} 添加成功! \n";
  558. } catch (\Exception $exception) {
  559. $transaction->rollBack();
  560. echo "{$mobile} 添加失败,报错:" . $exception->getMessage() . "\n";
  561. }
  562. }
  563. }
  564. }
  565. }