ItemController.php 24 KB

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