QuickGoods.Class.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <?php
  2. namespace JinDouYun\Controller\Goods;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Dao\GoodsCategory\DGoodsCategory;
  5. use JinDouYun\Dao\GoodsManage\DGoodsBrand;
  6. use JinDouYun\Dao\GoodsManage\DUnits;
  7. use JinDouYun\Dao\Merchant\DMerchantApply;
  8. use JinDouYun\Model\Goods\MQuickGoods;
  9. use JinDouYun\Model\Shop\MShop;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use Util\Common\ChineseCharacter;
  13. /**
  14. * 单店铺快速发布商品
  15. * 单位和规格的组合完全由前端进行生成
  16. * 单位(主/辅)
  17. * 单位+属性+价格(index unitId+specValueId...)
  18. * Class QuickGoods
  19. * @package JinDouYun\Controller\Goods
  20. */
  21. class QuickGoods extends BaseController
  22. {
  23. private $objMQuickGoods;
  24. public $shopId;
  25. public $shopName;
  26. private $isStore = false;//商户发布=>TRUE
  27. /**
  28. * QuickGoods constructor.
  29. * @param bool $isCheckAcl
  30. * @param bool $isMustLogin
  31. * @throws \Exception
  32. */
  33. public function __construct($isCheckAcl = true, $isMustLogin = true)
  34. {
  35. parent::__construct($isCheckAcl, $isMustLogin);
  36. $this->objMQuickGoods = new MQuickGoods($this->onlineEnterpriseId,$this->onlineUserId);
  37. }
  38. /**
  39. * 但店铺,查询默认店铺id,name
  40. */
  41. public function _initShop()
  42. {
  43. if ($this->isStore){
  44. $objMShop = new MShop($this->onlineEnterpriseId,$this->onlineUserId);
  45. $shopName = $objMShop->getShopNameById($this->shopId);
  46. $this->shopName = $shopName;
  47. }else{
  48. $shopResult = $this->objMQuickGoods->getShopData();
  49. if (!$shopResult->isSuccess()){
  50. parent::sendOutput($shopResult->getData(), ErrorCode::$dberror);
  51. }
  52. $shopData = $shopResult->getData();
  53. if (empty($shopData)){
  54. parent::sendOutput('请先创建店铺',ErrorCode::$paramError);
  55. }
  56. $this->shopId = isset($shopData['id']) ? $shopData['id'] : 0;
  57. $this->shopName = isset($shopData['name']) ? $shopData['name'] : '';
  58. return $shopData;
  59. }
  60. }
  61. /**
  62. * 公共字段
  63. *
  64. * @return array
  65. */
  66. public function commonFieldFilter()
  67. {
  68. $params = $this->request->getRawJson();
  69. if (empty($params)) {
  70. $this->sendOutput('参数为空', ErrorCode::$paramError);
  71. }
  72. ( isset($params['isStore']) && $params['isStore'] == true ) && $this->isStore = true;
  73. self::_initShop();
  74. $data = [
  75. 'title' => isset($params['title']) ? $params['title'] : null,
  76. 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : null,
  77. 'categoryPath' => isset($params['categoryPath']) ? $params['categoryPath'] : null,
  78. 'images' => isset($params['images']) ? json_encode($params['images']) : null,//商品图册json
  79. 'unitData' => isset($params['unitData']) ? $params['unitData'] : null,//商品单位
  80. 'specType' => isset($params['specType']) ? $params['specType'] : null,
  81. 'specMultiple' => isset($params['specMultiple']) ? $params['specMultiple'] : null,
  82. 'shopId' => $this->shopId,//商铺id
  83. 'shopName' => $this->shopName,//商铺名称
  84. ];
  85. foreach ($data as $key => $value) {
  86. if (empty($value)) {
  87. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  88. }
  89. }
  90. foreach ($data['specMultiple'] as $item){
  91. if ($item['isMaster']==StatusCode::$delete){
  92. if (empty((int) $item['conversion'])){
  93. parent::sendOutput('辅单位换算比例有误', ErrorCode::$paramError);
  94. }
  95. }
  96. }
  97. //商品名称转换搜索条件
  98. if(isset($data['title'])){
  99. $objChineseCharacter = new ChineseCharacter();
  100. $data['condition'] = $objChineseCharacter->getInitials(trim($data['title']));
  101. }
  102. $data['isStore'] = $this->isStore;
  103. $data['specGroup'] = isset($params['specGroup']) ? json_encode($params['specGroup']) : [];//规格组
  104. $data['brandId'] = isset($params['brandId']) ? $params['brandId'] : 0;
  105. $data['description'] = isset($params['description']) ? $params['description'] : '';
  106. $data['describe'] = isset($params['describe']) ? $params['describe'] : '';
  107. $data['expireTime'] = isset($params['expireTime']) ? $params['expireTime'] : 0;
  108. $data['tag'] = isset($params['tag']) ? $params['tag'] : '';
  109. $data['barCode'] = isset($params['barCode']) ? $params['barCode'] : '';//条码
  110. $data['link'] = isset($params['link']) ? $params['link'] : '';
  111. $data['noSalesShop'] = isset($params['noSalesShop']) ? $params['noSalesShop'] : ''; //禁止销售店铺
  112. $data['assistCategoryId'] = isset($params['assistCategoryId']) ? $params['assistCategoryId'] : '';
  113. $data['assistCategoryPath'] = isset($params['assistCategoryPath']) ? json_encode($params['assistCategoryPath']) : [];
  114. //商品
  115. $data['sort'] = isset($params['sort']) ? $params['sort'] : 9999;//商品排序
  116. $data['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete;
  117. $data['createUserName'] = isset($params['createUserName']) ? $params['createUserName'] : '';
  118. $storage = isset($params['storage']) ? $params['storage'] : '';//货架编码
  119. $data['extends'] = json_encode(['storage'=>$storage]);//货架编码
  120. isset($params['deliverySupIds']) && $data['deliverySupIds'] = $params['deliverySupIds'];
  121. isset($params['expressType']) && $data['expressType'] = $params['expressType'];
  122. isset($params['ruleId']) && $data['ruleId'] = $params['ruleId'];
  123. isset($params['expressFee']) && $data['expressFee'] = $params['expressFee'];
  124. isset($params['showExpress']) && $data['showExpress'] = $params['showExpress'];
  125. (isset($this->supplierId) && !empty($this->supplierId)) && $data['supplierId'] = $this->supplierId;
  126. $data['isEq'] = isset($params['isEq']) ? $params['isEq'] : null;
  127. $data['merchantId'] = getArrayItem($params, 'merchantId', 0);
  128. $data['isShield'] = getArrayItem($params,'isShield',StatusCode::$delete);
  129. $data['notArea'] = json_encode(getArrayItem($params,'notArea',null));
  130. $data['notCustomerType'] = getArrayItem($params,'notCustomerType','');
  131. $data['notCustomer'] = getArrayItem($params,'notCustomer','');
  132. $data['isDistribution'] = getArrayItem($params,'isDistribution',StatusCode::$delete);
  133. $data['createUserName'] = getArrayItem($params,'createUserName','');
  134. return $data;
  135. }
  136. /**
  137. * 添加商品基础资料
  138. * @throws \Exception
  139. */
  140. public function addBasicAndPublishGoods()
  141. {
  142. $data = self::commonFieldFilter();
  143. //添加商品基础资料
  144. $result = $this->objMQuickGoods->addBasicAndPublishGoods($data);
  145. if ($result->isSuccess()) {
  146. parent::sendOutput($result->getData());
  147. }
  148. parent::sendOutput($result->getData(), $result->getErrorCode());
  149. }
  150. /**
  151. * 商品及商品基础资料详情
  152. * @throws \Exception
  153. */
  154. public function getQuickGoodsInfo()
  155. {
  156. $goodsId = $this->request->param('request_id');
  157. if (!$goodsId) {
  158. $this->sendOutput('参数错误', ErrorCode::$paramError);
  159. }
  160. $result = $this->objMQuickGoods->getQuickGoodsInfo($goodsId);
  161. if ($result->isSuccess()) {
  162. $resultData = $result->getData();
  163. $this->sendOutput($resultData);
  164. }
  165. $this->sendOutput($result->getData(), $result->getErrorCode());
  166. }
  167. /**
  168. * 编辑
  169. * @throws \Exception
  170. */
  171. public function editQuickGoods()
  172. {
  173. $data = self::commonFieldFilter();
  174. $params = $this->request->getRawJson();
  175. if (!isset($params['id']) || empty($params['id'])){
  176. parent::sendOutput('id参数错误', ErrorCode::$paramError);
  177. }
  178. if (!isset($params['basicGoodsId']) || empty($params['basicGoodsId'])){
  179. parent::sendOutput('basicGoodsId参数错误', ErrorCode::$paramError);
  180. }
  181. $result = $this->objMQuickGoods->editQuickGoods($data,$params['id'],$params['basicGoodsId']);
  182. if ($result->isSuccess()) {
  183. parent::sendOutput($result->getData());
  184. }
  185. parent::sendOutput($result->getData(), $result->getErrorCode());
  186. }
  187. /**
  188. * 接收导入数据参数
  189. * @throws \Exception
  190. */
  191. public function getGoodsQuickImportParams()
  192. {
  193. //获取数据文件
  194. $params = $this->request->getRawJson();
  195. //企业id
  196. $enterpriseId = $this->onlineEnterpriseId;
  197. //商品图片
  198. $images = [];
  199. //多单位
  200. $twoUnit = true;
  201. //引用dao
  202. $objDGoodsCategory = new DGoodsCategory();
  203. $objDGoodsCategory->setTable('qianniao_goods_category_' . $enterpriseId);
  204. $objDGoodsBrand = new DGoodsBrand();
  205. $objDGoodsBrand->setTable('qianniao_goods_brand_' . $enterpriseId);
  206. $objDUnits = new DUnits();
  207. $objDUnits->setTable('qianniao_units_' . $enterpriseId);
  208. $objDMerchantApply = new DMerchantApply();
  209. //获取数据
  210. $postArray = [];
  211. foreach ($params as $value) {
  212. $goodsArray = $value;
  213. //商品信息
  214. $goodsName = isset($goodsArray['goodsName']) ? trim($goodsArray['goodsName']) : '';//商品名称
  215. $describe = isset($goodsArray['describe']) ? trim($goodsArray['describe']) : '';//商品卖点
  216. $categoryName = isset($goodsArray['categoryName']) ? trim($goodsArray['categoryName']) : ''; //分类名称
  217. $categoryTwo = isset($goodsArray['categoryTwo']) ? trim($goodsArray['categoryTwo']) : '';//二级分类名称
  218. $categoryThree = isset($goodsArray['categoryThree']) ? trim($goodsArray['categoryThree']) : '';//三级分类名称
  219. // //商户名称
  220. $merchantName = isset($goodsArray['merchantName']) ? trim($goodsArray['merchantName']) : '';//商户名称
  221. // $brandName = isset($goodsArray['brandName']) ? trim($goodsArray['brandName']) : '';//品牌名称
  222. $isEq = isset($goodsArray['isEq']) ? trim($goodsArray['isEq']) : 4;//是否抄码
  223. $description = isset($goodsArray['description']) ? '<p>' . trim($goodsArray['description']) . '</p>' : '';//商品详情
  224. //主单位信息
  225. $skuName = isset($goodsArray['skuName']) ? trim($goodsArray['skuName']) : '无';//单位名称
  226. $salePrice = isset($goodsArray['salePrice']) ? trim($goodsArray['salePrice']) : 1;//销售价
  227. $memberPrice = isset($goodsArray['memberPrice']) ? trim($goodsArray['memberPrice']) : 1;//会员价
  228. $barCode = isset($goodsArray['barCode']) ? trim($goodsArray['barCode']) : '';//主单位条码
  229. $salePriceTrue = isset($goodsArray['salePriceTrue']) ? trim($goodsArray['salePriceTrue']) : bcmul($salePrice, 1.2, 2);//市场价格
  230. //辅单位信息
  231. if ($twoUnit) {
  232. $skuNameTwo = isset($goodsArray['skuNameTwo']) ? trim($goodsArray['skuNameTwo']) : '';//辅单位
  233. $barCodeTwo = isset($goodsArray['barCodeTwo']) ? trim($goodsArray['barCodeTwo']) : '';//辅单位条码
  234. $salePriceTwo = isset($goodsArray['salePriceTwo']) ? trim($goodsArray['salePriceTwo']) : 1;//辅单位销售价格
  235. $conversion = isset($goodsArray['conversion']) ? trim($goodsArray['conversion']) : 0;//辅单位换算比例
  236. $salePriceTwoTrue = isset($goodsArray['salePriceTwoTrue']) ? trim($goodsArray['salePriceTwoTrue']) : bcmul($salePriceTwo, 1.2, 2);//辅单位市场价格
  237. }
  238. if (empty($goodsName)) {
  239. continue;
  240. }
  241. /***商户数据***/
  242. if (!empty($merchantName)) {
  243. //查询商户是否存在
  244. $merchantSelect = [
  245. 'name' => $merchantName,
  246. ];
  247. $dbResult = $objDMerchantApply->get($merchantSelect);
  248. if ($dbResult === false) {
  249. exit($objDGoodsCategory->error());
  250. }
  251. $merchantId = !empty($dbResult['id']) ? empty($dbResult['id']) : 0 ;
  252. unset($dbResult);
  253. } else {
  254. $merchantId = 0;
  255. }
  256. /***首分类数据***/
  257. $categoryId = 1;
  258. $categoryPath = 1;
  259. if (!empty($categoryName)) {
  260. //查询分类是否存在
  261. $categorySelect = [
  262. 'title' => $categoryName,
  263. ];
  264. $dbResult = $objDGoodsCategory->get($categorySelect);
  265. if ($dbResult === false) {
  266. exit($objDGoodsCategory->error());
  267. }
  268. $category = $dbResult;
  269. unset($dbResult);
  270. if (empty($category)) {
  271. $categoryInsert = [
  272. 'sort' => 0,
  273. 'title' => $categoryName,
  274. 'pid' => 0,
  275. 'enableStatus' => StatusCode::$standard,
  276. 'deleteStatus' => StatusCode::$standard,
  277. 'createTime' => time(),
  278. 'updateTime' => time(),
  279. ];
  280. $dbResult = $objDGoodsCategory->insert($categoryInsert);
  281. if ($dbResult === false) {
  282. exit($objDGoodsCategory->error());
  283. }
  284. $categoryId = $dbResult;
  285. $categoryPath = $dbResult;
  286. unset($dbResult);
  287. } else {
  288. $categoryId = ['id'];
  289. if(!empty($category['link'])){
  290. $categoryPath = $category['link'] . ',' . $category['id'];
  291. }else{
  292. $categoryPath = $category['id'];
  293. }
  294. }
  295. /***二级分类数据***/
  296. if (!empty($categoryTwo)) {
  297. //查询分类是否存在
  298. $categorySelect = [
  299. 'title' => $categoryTwo,
  300. ];
  301. $dbResult = $objDGoodsCategory->get($categorySelect);
  302. if ($dbResult === false) {
  303. exit($objDGoodsCategory->error());
  304. }
  305. $category = $dbResult;
  306. unset($dbResult);
  307. if (empty($category)) {
  308. $categoryInsert = [
  309. 'sort' => 0,
  310. 'title' => $categoryTwo,
  311. 'pid' => $categoryId,
  312. 'link' => $categoryPath,
  313. 'enableStatus' => StatusCode::$standard,
  314. 'deleteStatus' => StatusCode::$standard,
  315. 'createTime' => time(),
  316. 'updateTime' => time(),
  317. ];
  318. $dbResult = $objDGoodsCategory->insert($categoryInsert);
  319. if ($dbResult === false) {
  320. exit($objDGoodsCategory->error());
  321. }
  322. $categoryId = $dbResult;
  323. $categoryPath = $categoryId . ',' . $dbResult;
  324. unset($dbResult);
  325. } else {
  326. $categoryId = $category['id'];
  327. if(!empty($category['link'])){
  328. $categoryPath = $category['link'] . ',' . $category['id'];
  329. }else{
  330. $categoryPath = $category['id'];
  331. }
  332. }
  333. /***三级分类数据***/
  334. if (!empty($categoryThree)) {
  335. //查询分类是否存在
  336. $categorySelect = [
  337. 'title' => $categoryThree,
  338. ];
  339. $dbResult = $objDGoodsCategory->get($categorySelect);
  340. if ($dbResult === false) {
  341. exit($objDGoodsCategory->error());
  342. }
  343. $category = $dbResult;
  344. unset($dbResult);
  345. if (empty($category)) {
  346. $categoryInsert = [
  347. 'sort' => 0,
  348. 'title' => $categoryThree,
  349. 'pid' => $categoryId,
  350. 'link' => $categoryPath,
  351. 'enableStatus' => StatusCode::$standard,
  352. 'deleteStatus' => StatusCode::$standard,
  353. 'createTime' => time(),
  354. 'updateTime' => time(),
  355. ];
  356. $dbResult = $objDGoodsCategory->insert($categoryInsert);
  357. if ($dbResult === false) {
  358. exit($objDGoodsCategory->error());
  359. }
  360. $categoryId = $dbResult;
  361. $categoryPath = $categoryId . ',' . $categoryId . ',' . $dbResult;
  362. unset($dbResult);
  363. } else {
  364. $categoryId = $category['id'];
  365. if(!empty($category['link'])){
  366. $categoryPath = $category['link'] . ',' . $category['id'];
  367. }else{
  368. $categoryPath = $category['id'];
  369. }
  370. }
  371. }
  372. }
  373. }
  374. $categoryPath = trim($categoryPath, ',');
  375. /***品牌数据***/
  376. if (!empty($brandName)) {
  377. //查询品牌是否存在
  378. $brandSelect = [
  379. 'title' => $brandName
  380. ];
  381. $dbResult = $objDGoodsBrand->get($brandSelect);
  382. if ($dbResult === false) {
  383. exit($objDGoodsBrand->error());
  384. }
  385. $brand = $dbResult;
  386. unset($dbResult);
  387. if (empty($brand)) {
  388. $brandInsert = [
  389. 'title' => $brandName,
  390. 'images' => null,
  391. 'sort' => 0,
  392. 'enableStatus' => StatusCode::$standard,
  393. 'createTime' => time(),
  394. 'updateTime' => time(),
  395. ];
  396. $dbResult = $objDGoodsBrand->insert($brandInsert);
  397. if ($dbResult === false) {
  398. exit($objDGoodsBrand->error());
  399. }
  400. $brandId = $dbResult;
  401. unset($dbResult);
  402. } else {
  403. $brandId = $brand['id'];
  404. }
  405. } else {
  406. $brandId = 1;
  407. }
  408. /***单位数据***/
  409. $skuId = NULL;
  410. if (!empty($skuName)) {
  411. //查询单位是否存在
  412. $skuSelect = [
  413. 'unitName' => $skuName
  414. ];
  415. $dbResult = $objDUnits->get($skuSelect);
  416. if ($dbResult === false) {
  417. exit($objDUnits->error());
  418. }
  419. $sku = $dbResult;
  420. unset($dbResult);
  421. if (empty($sku)) {
  422. $skuInsert = [
  423. 'unitName' => $skuName,
  424. 'enableStatus' => StatusCode::$standard,
  425. 'createTime' => time(),
  426. 'updateTime' => time(),
  427. ];
  428. $dbResult = $objDUnits->insert($skuInsert);
  429. if ($dbResult === false) {
  430. exit($objDUnits->error());
  431. }
  432. $skuId = $dbResult;
  433. unset($dbResult);
  434. } else {
  435. $skuId = $sku['id'];
  436. }
  437. }
  438. $skuIdTwo = NULL;
  439. if (!empty($skuNameTwo)) {
  440. //查询单位是否存在
  441. $skuSelect = [
  442. 'unitName' => $skuNameTwo
  443. ];
  444. $dbResult = $objDUnits->get($skuSelect);
  445. if ($dbResult === false) {
  446. exit($objDUnits->error());
  447. }
  448. $sku = $dbResult;
  449. unset($dbResult);
  450. if (empty($sku)) {
  451. $skuInsert = [
  452. 'unitName' => $skuNameTwo,
  453. 'enableStatus' => StatusCode::$standard,
  454. 'createTime' => time(),
  455. 'updateTime' => time(),
  456. ];
  457. $dbResult = $objDUnits->insert($skuInsert);
  458. if ($dbResult === false) {
  459. exit($objDUnits->error());
  460. }
  461. $skuIdTwo = $dbResult;
  462. unset($dbResult);
  463. } else {
  464. $skuIdTwo = $sku['id'];
  465. }
  466. }
  467. $postData = [
  468. 'merchantId' => $merchantId,
  469. 'categoryPath' => $categoryPath,
  470. 'categoryId' => $categoryId,
  471. 'assistCategoryPath' =>[],//商品辅助的单位
  472. 'assistCategoryId' => '',//商品辅助的单位id
  473. 'title' => $goodsName,
  474. 'storage' => '',
  475. 'delUnitIds' =>[],
  476. 'delSpecSkuIds' =>[],
  477. 'specType' => 1,
  478. 'createUserName' => '',
  479. 'specGroup' =>[],
  480. 'specMultiple' =>
  481. [
  482. [
  483. 'barCode' => $barCode,
  484. 'weight' => '',
  485. 'isDefault' => 5,
  486. 'unitId' =>$skuIdTwo,
  487. 'unitName' => $skuName,
  488. 'isMaster' => 5,
  489. 'conversion' => $conversion,
  490. 'specImage' => '',
  491. 'specGroup' =>[],
  492. 'salePrice' =>
  493. [
  494. 'conversion' => $conversion,
  495. 'unitName' => $skuName,
  496. 'unitId' => $skuId,
  497. 'isMaster' => 5,
  498. 'deleteStatus' => 4,
  499. 'enabledLadder' => 0,
  500. 'salePriceAreaType' => 1,
  501. 'salePrice' => $salePrice,
  502. 'memberPrice'=> $memberPrice,
  503. 'ladderPrice' =>[],
  504. 'marketPrice' =>$salePriceTrue,
  505. 'setNum' => 1,
  506. ],
  507. 'customerTypePrice' =>[],
  508. 'customerPrice' =>[],
  509. ],
  510. ],
  511. 'unitData' =>
  512. [
  513. [
  514. 'barCode' => $barCode,
  515. 'weight' => '',
  516. 'isMaster' => 5,
  517. 'isDefault' => 5,
  518. 'unitName' => $skuName,
  519. 'unitId' => $skuId,
  520. ],
  521. ],
  522. 'describe' => $describe,
  523. 'code' => '',
  524. 'barCode' => $barCode,
  525. 'weight' => '',
  526. 'expireTime' => '',
  527. 'brandId' => $brandId,
  528. 'tag' => '',
  529. 'description' => $description,
  530. 'noSalesShop' => '',
  531. 'images' =>$images,
  532. 'enableStatus' => 5,
  533. 'isEq' => $isEq,
  534. 'isDistribution' => 4,
  535. 'isShield' => 4,
  536. 'deliverySupIds' => '',
  537. 'expressType' => 1,
  538. 'expressFee' => '',
  539. 'showExpress' => '',
  540. 'ruleId' => '',
  541. 'notArea' =>[],
  542. 'notCustomerType' => '',
  543. 'notCustomer' => '',
  544. 'isStore' => '',
  545. ];
  546. $postArray[] = $postData;
  547. }
  548. return $postArray;
  549. }
  550. /**
  551. * 单商铺导入商品基础数据
  552. * @throws \Exception
  553. */
  554. public function goodsQuickImport()
  555. {
  556. //把页面传来的参数对应到符合的字段中全部传递过来;
  557. $paramsArray = self::getGoodsQuickImportParams();
  558. if (empty($paramsArray)) {
  559. $this->sendOutput('参数为空', ErrorCode::$paramError);
  560. }
  561. $goodsBasic = [];
  562. foreach ($paramsArray as $params) {
  563. ( isset($params['isStore']) && $params['isStore'] == true ) && $this->isStore = true;
  564. self::_initShop();
  565. $goodsBasicData = [
  566. 'title' => isset($params['title']) ? $params['title'] : null,
  567. 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : null,
  568. 'categoryPath' => isset($params['categoryPath']) ? $params['categoryPath'] : null,
  569. 'images' => isset($params['images']) ? json_encode($params['images']) : null,//商品图册json
  570. 'unitData' => isset($params['unitData']) ? $params['unitData'] : null,//商品单位
  571. 'specType' => isset($params['specType']) ? $params['specType'] : null,
  572. 'specMultiple' => isset($params['specMultiple']) ? $params['specMultiple'] : null,
  573. 'shopId' => $this->shopId,//商铺id
  574. 'shopName' => $this->shopName,//商铺名称
  575. ];
  576. foreach ($goodsBasicData as $key => $value) {
  577. if (empty($value)) {
  578. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  579. }
  580. }
  581. foreach ($goodsBasicData['specMultiple'] as $item){
  582. if ($item['isMaster']==StatusCode::$delete){
  583. if (empty((int) $item['conversion'])){
  584. parent::sendOutput('辅单位换算比例有误', ErrorCode::$paramError);
  585. }
  586. }
  587. }
  588. //商品名称转换搜索条件
  589. if(isset($goodsBasicData['title'])){
  590. $objChineseCharacter = new ChineseCharacter();
  591. $goodsBasicData['condition'] = $objChineseCharacter->getInitials(trim($goodsBasicData['title']));
  592. }
  593. $goodsBasicData['isStore'] = $this->isStore;
  594. $goodsBasicData['specGroup'] = isset($params['specGroup']) ? json_encode($params['specGroup']) : [];//规格组
  595. $goodsBasicData['brandId'] = isset($params['brandId']) ? $params['brandId'] : 0;
  596. $goodsBasicData['description'] = isset($params['description']) ? $params['description'] : '';
  597. $goodsBasicData['describe'] = isset($params['describe']) ? $params['describe'] : '';
  598. $goodsBasicData['expireTime'] = isset($params['expireTime']) ? $params['expireTime'] : 0;
  599. $goodsBasicData['memberPrice'] = isset($params['memberPrice']) ? $params['memberPrice'] : 0;
  600. $goodsBasicData['tag'] = isset($params['tag']) ? $params['tag'] : '';
  601. $goodsBasicData['barCode'] = isset($params['barCode']) ? $params['barCode'] : '';//条码
  602. $goodsBasicData['link'] = isset($params['link']) ? $params['link'] : '';
  603. $goodsBasicData['noSalesShop'] = isset($params['noSalesShop']) ? $params['noSalesShop'] : ''; //禁止销售店铺
  604. $goodsBasicData['assistCategoryId'] = isset($params['assistCategoryId']) ? $params['assistCategoryId'] : '';
  605. $goodsBasicData['assistCategoryPath'] = isset($params['assistCategoryPath']) ? json_encode($params['assistCategoryPath']) : [];
  606. //商品
  607. $goodsBasicData['sort'] = isset($params['sort']) ? $params['sort'] : 9999;//商品排序
  608. $goodsBasicData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete;
  609. $goodsBasicData['createUserName'] = isset($params['createUserName']) ? $params['createUserName'] : '';
  610. $storage = isset($params['storage']) ? $params['storage'] : '';//货架编码
  611. $goodsBasicData['extends'] = json_encode(['storage'=>$storage]);//货架编码
  612. isset($params['deliverySupIds']) && $goodsBasicData['deliverySupIds'] = $params['deliverySupIds'];
  613. isset($params['expressType']) && $goodsBasicData['expressType'] = $params['expressType'];
  614. isset($params['ruleId']) && $goodsBasicData['ruleId'] = $params['ruleId'];
  615. isset($params['expressFee']) && $goodsBasicData['expressFee'] = $params['expressFee'];
  616. isset($params['showExpress']) && $goodsBasicData['showExpress'] = $params['showExpress'];
  617. (isset($this->supplierId) && !empty($this->supplierId)) && $goodsBasicData['supplierId'] = $this->supplierId;
  618. $goodsBasicData['isEq'] = isset($params['isEq']) ? $params['isEq'] : null;
  619. $goodsBasicData['merchantId'] = getArrayItem($params, 'merchantId', 0);
  620. $goodsBasicData['isShield'] = getArrayItem($params,'isShield',StatusCode::$delete);
  621. $goodsBasicData['notArea'] = json_encode(getArrayItem($params,'notArea',null));
  622. $goodsBasicData['notCustomerType'] = getArrayItem($params,'notCustomerType','');
  623. $goodsBasicData['notCustomer'] = getArrayItem($params,'notCustomer','');
  624. $goodsBasicData['isDistribution'] = getArrayItem($params,'isDistribution',StatusCode::$delete);
  625. $goodsBasicData['createUserName'] = getArrayItem($params,'createUserName','');
  626. $goodsBasic[] = $goodsBasicData;
  627. }
  628. unset($goodsBasicData);
  629. $total = 0;
  630. $true = 0;
  631. $false = 0;
  632. foreach ($goodsBasic as $key => $goodsBasicData) {
  633. $result = $this->objMQuickGoods->addBasicAndPublishGoods($goodsBasicData);
  634. if (!$result->isSuccess()) {
  635. $false++;
  636. } else {
  637. $true++;
  638. }
  639. $total++;
  640. }
  641. $return = "共导入'$total'条商品,成功'$true'条商品,失败'$false'条商品";
  642. parent::sendOutput($return);
  643. }
  644. }