Goods.Class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?php
  2. /**
  3. * 商品管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/30
  7. * Time: 13:54
  8. */
  9. namespace JinDouYun\Controller\Goods;
  10. use JinDouYun\Controller\Common\Logger;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use Mall\Framework\Core\StatusCode;
  14. use JinDouYun\Controller\BaseController;
  15. use JinDouYun\Model\Goods\MGoods;
  16. use Monolog\Handler\IFTTTHandler;
  17. /**
  18. * Class Goods
  19. * @package JinDouYun\Controller\Goods
  20. */
  21. class Goods extends BaseController
  22. {
  23. /**
  24. * @var MGoods
  25. */
  26. private $objMGoods;
  27. /**
  28. * Goods 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->objMGoods = new MGoods($this->onlineEnterpriseId, false, $this->onlineUserId);
  37. }
  38. /**
  39. * 添加和编辑商品管理公共字段处理方法
  40. *
  41. * @return array
  42. */
  43. public function commonFieldFilter()
  44. {
  45. $params = $this->request->getRawJson();
  46. if (empty($params)) {
  47. $this->sendOutput('参数为空', ErrorCode::$paramError);
  48. }
  49. $goodsData = [
  50. 'basicGoodsId' => isset($params['goodsBasicId']) ? $params['goodsBasicId'] : '',//基本资料id
  51. 'goodsName' => isset($params['goodsName']) ? $params['goodsName'] : '',//基本资料商品名称
  52. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',//商铺id
  53. 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',//商铺名称
  54. 'images' => isset($params['images']) ? json_encode($params['images']) : '',
  55. 'specType' => isset($params['specType']) ? $params['specType'] : null,//规格类型
  56. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete,
  57. //'serviceInfo' => isset($params['serviceInfo']) ? $params['serviceInfo'] : '',
  58. 'priceData' => isset($params['price']) ? $params['price'] : '',//接json值
  59. //'specification' => isset($params['specification']) ? json_encode($params['specification']) : '',//接json值
  60. 'createUserName' => isset($params['createUserName']) ? $params['createUserName'] : '',//添加商品人名称
  61. ];
  62. foreach ($goodsData as $key => $value) {
  63. if (empty($value) && $value !== 0) {
  64. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  65. }
  66. }
  67. isset($params['deliverySupIds']) && $goodsData['deliverySupIds'] = $params['deliverySupIds'];
  68. isset($params['expressType']) && $goodsData['expressType'] = $params['expressType'];
  69. isset($params['ruleId']) && $goodsData['ruleId'] = $params['ruleId'];
  70. isset($params['expressFee']) && $goodsData['expressFee'] = $params['expressFee'];
  71. isset($params['showExpress']) && $goodsData['showExpress'] = $params['showExpress'];
  72. $goodsData['content'] = isset($params['content']) ? $params['content'] : '';
  73. $goodsData['isRecommend'] = isset($params['isRecommend']) ? $params['isRecommend'] : StatusCode::$standard;
  74. $goodsData['createTime'] = time();
  75. $goodsData['updateTime'] = time();
  76. $goodsData['deleteStatus'] = StatusCode::$standard;
  77. $goodsData['sort'] = isset($params['sort']) ? $params['sort'] : 0;
  78. $goodsData['isShield'] = getArrayItem($params,'isShield',StatusCode::$delete);
  79. $goodsData['notArea'] = json_encode(getArrayItem($params,'notArea',null));
  80. $goodsData['notCustomerType'] = getArrayItem($params,'notCustomerType','');
  81. $goodsData['notCustomer'] = getArrayItem($params,'notCustomer','');
  82. $goodsData['isDistribution'] = getArrayItem($params,'isDistribution',StatusCode::$delete);
  83. $goodsData['support'] = getArrayItem($params,'support',[]);
  84. $goodsData['support'] = implode(',',$goodsData['support'] );
  85. $goodsData['goodsGroups'] = getArrayItem($params,'goodsGroups');//商品分组
  86. $goodsData['showMinUnitPrice'] = getArrayItem($params,'showMinUnitPrice',4);//属性最小单位价格是否展示 默认 4 不展示
  87. if ( !empty($goodsData['goodsGroups']) ){
  88. $goodsData['goodsGroups'] = implode(',', $goodsData['goodsGroups']);
  89. }
  90. return $goodsData;
  91. }
  92. /**
  93. * 添加商品
  94. * @throws \Exception
  95. */
  96. public function addGoods()
  97. {
  98. $goodsData = $this->commonFieldFilter();
  99. $result = $this->objMGoods->addGoods($goodsData);
  100. if ($result->isSuccess()) {
  101. parent::sendOutput($result->getData());
  102. }
  103. parent::sendOutput($result->getData(), $result->getErrorCode());
  104. }
  105. /**
  106. * @throws \Exception
  107. */
  108. public function getGoodsInfo()
  109. {
  110. $goodsId = $this->request->param('request_id');
  111. if (!$goodsId) {
  112. $this->sendOutput('参数错误', ErrorCode::$paramError);
  113. }
  114. $params = $this->request->getRawJson();
  115. $userCenterId = 0;
  116. if (isset($params['userCenterId']) && !empty($params['userCenterId'])) {
  117. //后台选择了客户
  118. $this->objMGoods = new MGoods($this->onlineEnterpriseId, false, $params['userCenterId']);
  119. $userCenterId = $params['userCenterId'];
  120. }
  121. $result = $this->objMGoods->getGoodsInfo($goodsId,$userCenterId);
  122. if ($result->isSuccess()) {
  123. $resultData = $result->getData();
  124. $this->sendOutput($resultData);
  125. }
  126. $this->sendOutput($result->getData(), $result->getErrorCode());
  127. }
  128. /**
  129. * 更新商品上下架
  130. * @throws \Exception
  131. */
  132. public function updateEnableStatus()
  133. {
  134. $params = $this->request->getRawJson();
  135. if (empty($params['id']) && empty($params['enableStatus'])) {
  136. $this->sendOutput('参数为空', ErrorCode::$paramError);
  137. }
  138. $result = $this->objMGoods->updateEnableStatus($params);
  139. if ($result->isSuccess()) {
  140. parent::sendOutput($result->getData());
  141. }
  142. parent::sendOutput($result->getData(), $result->getErrorCode());
  143. }
  144. /**
  145. * 编辑商品
  146. */
  147. public function editGoods()
  148. {
  149. $goodsId = $this->request->param('request_id');
  150. if (empty($goodsId)) {
  151. $this->sendOutput('参数错误', ErrorCode::$paramError);
  152. }
  153. $goodsData = $this->commonFieldFilter();
  154. $goodsData['id'] = $goodsId;
  155. unset($goodsData['createTime']);
  156. $result = $this->objMGoods->editGoods($goodsData);
  157. if ($result->isSuccess()) {
  158. parent::sendOutput($result->getData());
  159. }
  160. parent::sendOutput($result->getData(), $result->getErrorCode());
  161. }
  162. /**
  163. * Doc: (des="审核商品")
  164. * User: XMing
  165. * Date: 2020/12/7
  166. * Time: 11:31 上午
  167. */
  168. public function audit()
  169. {
  170. $goodsId = $this->request->param('request_id');
  171. if (empty($goodsId)) {
  172. $this->sendOutput('参数错误', ErrorCode::$paramError);
  173. }
  174. $result = $this->objMGoods->audit($goodsId);
  175. if ($result->isSuccess()) {
  176. parent::sendOutput($result->getData());
  177. }
  178. parent::sendOutput($result->getData(), $result->getErrorCode());
  179. }
  180. /**
  181. * 删除商品
  182. */
  183. public function delGoods()
  184. {
  185. $goodsId = $this->request->param('request_id');
  186. if (!$goodsId) {
  187. $this->sendOutput('参数错误', ErrorCode::$paramError);
  188. }
  189. $result = $this->objMGoods->delGoods($goodsId);
  190. if ($result->isSuccess()) {
  191. parent::sendOutput($result->getData());
  192. }
  193. parent::sendOutput($result->getData(), $result->getErrorCode());
  194. }
  195. /**
  196. * 后台所有商品列表
  197. * @throws \Exception
  198. */
  199. public function getAllGoods()
  200. {
  201. $params = $this->request->getRawJson();
  202. if (empty($params)) {
  203. $this->sendOutput('参数为空', ErrorCode::$paramError);
  204. }
  205. if (isset($this->shopId) && !empty($this->shopId)) {
  206. $selectParams['shopId'] = $this->shopId;
  207. }
  208. if (isset($params['shopId']) && !empty($params['shopId'])) {
  209. $selectParams['shopId'] = $params['shopId'];
  210. }
  211. if (isset($params['isOption']) && !empty($params['isOption'])){
  212. $selectParams['isOption'] = $params['isOption'];
  213. }
  214. //ifMerchant (4 采购单 5商户入库单)
  215. if( isset($params['ifMerchant']) && !empty($params['ifMerchant']) ){
  216. $selectParams['ifMerchant'] = $params['ifMerchant'];
  217. }
  218. if( isset($params['merchantId']) && !empty($params['merchantId']) ){
  219. $selectParams['merchantId'] = $params['merchantId'];
  220. }
  221. //销售中 页面显示有库存,已上架,的商品。
  222. if (isset($params['inSales']) && !empty($params['inSales'])) {
  223. $selectParams['enableStatus'] = StatusCode::$standard;
  224. $selectParams['inStock'] = StatusCode::$standard;
  225. }
  226. //有无库存 inStock 5仓库中 4已售空
  227. if (isset($params['inStock']) && !empty($params['inStock'])) {
  228. if ($params['inStock'] == StatusCode::$standard) {
  229. //仓库中:有库存,未上架的商品列表
  230. $selectParams['enableStatus'] = StatusCode::$delete;
  231. $selectParams['inStock'] = $params['inStock'];
  232. } else {
  233. //已售罄:库存为0,自动下架的商品列表
  234. $selectParams['inStock'] = $params['inStock'];
  235. }
  236. }
  237. // 分页
  238. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  239. $selectParams['limit'] = $pageParams['limit'];
  240. $selectParams['offset'] = $pageParams['offset'];
  241. if (isset($params['enableStatus'])) {
  242. $selectParams['enableStatus'] = $params['enableStatus'];
  243. }
  244. // 导出
  245. $is_export = false;
  246. if (isset($params['export']) && $params['export'] == 1) $is_export = true;
  247. $selectParams['auditStatus'] = StatusCode::$auditStatus['auditPass'];
  248. if (isset($params['auditStatus']) && !empty($params['auditStatus'])){
  249. $selectParams['auditStatus'] = $params['auditStatus'];
  250. }
  251. $selectParams['supplierId'] = $this->supplierId;
  252. $result = $this->objMGoods->getAllGoods($selectParams, '*', 'topTime desc, sort desc,createTime desc', $is_export);
  253. if ($result->isSuccess()) {
  254. $returnData = $result->getData();
  255. $pageData = [
  256. 'pageIndex' => $params['page'],
  257. 'pageSize' => $params['pageSize'],
  258. 'pageTotal' => $returnData['total'],
  259. ];
  260. parent::sendOutput($returnData['data'], 0, $pageData);
  261. }
  262. parent::sendOutput($result->getData(), $result->getErrorCode());
  263. }
  264. /**
  265. * 商品列表页
  266. */
  267. public function getAllGoodsList()
  268. {
  269. $paramsData = $this->request->getRawJson();
  270. $params = [
  271. 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
  272. 'page' => isset($paramsData['page']) ? $paramsData['page'] : 1,
  273. ];
  274. $offset = ($params['page'] - 1) * $params['pageSize'];
  275. $selectParams = [
  276. 'limit' => $params['pageSize'],
  277. 'offset' => $offset,
  278. ];
  279. foreach ($selectParams as $key => $value) {
  280. if (empty($value) && $value !== 0) {
  281. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  282. }
  283. }
  284. // keywordType 1全部商品 2(销售中 上架且有库存) 3(已售罄 上架无库存) 4(仓库中 下架)
  285. $selectParams['keywordType'] = getArrayItem($paramsData,'keywordType',1);
  286. $selectParams['keyword'] = getArrayItem($paramsData,'keyword'); // 商品名称或商品编码
  287. $selectParams['categoryId'] = getArrayItem($paramsData,'categoryId'); // 商品分类
  288. $selectParams['brandId'] = getArrayItem($paramsData,'brandId'); //商品品牌
  289. $selectParams['enableStatus']= getArrayItem($paramsData,'enableStatus'); // 上下架(5上架 4下架)
  290. $selectParams['ifMerchant']= getArrayItem($paramsData,'ifMerchant'); //ifMerchant (4 采购单 5商户入库单)
  291. $selectParams['merchantId']= getArrayItem($paramsData,'merchantId'); //
  292. $export = getArrayItem($paramsData,'export',''); // 导出
  293. if(isset($this->shopId) && !empty($this->shopId)){
  294. $selectParams['shopId'] = $this->shopId ;
  295. }else{
  296. $selectParams['shopId'] = getArrayItem($paramsData,'shopId',0); //销售店铺
  297. }
  298. $selectParams['categoryPath']= getArrayItem($paramsData,'categoryPath');
  299. $goodsData = $this->objMGoods->getAllGoodsList($selectParams,$export);
  300. if ($goodsData->isSuccess()) {
  301. $returnData = $goodsData->getData();
  302. $pageData = [
  303. 'pageIndex' => $params['page'],
  304. 'pageSize' => $params['pageSize'],
  305. 'pageTotal' => $returnData['total'],
  306. ];
  307. parent::sendOutput($returnData['data'], 0, $pageData);
  308. }
  309. parent::sendOutput($goodsData->getData(), ErrorCode::$dberror);
  310. }
  311. /**
  312. * 格式化所有商品搜索条件
  313. * @throws \Exception
  314. */
  315. public function formatGoodsCondition()
  316. {
  317. $params = $this->request->param('request_id');
  318. if (empty($params)) {
  319. parent::sendOutput('参数错误', ErrorCode::$paramError);
  320. }
  321. $result = $this->objMGoods->formatGoodsCondition($params);
  322. if (!$result->isSuccess()) {
  323. parent::sendOutput($result->getData(), $result->getErrorCode());
  324. }
  325. parent::sendOutput($result->getData());
  326. }
  327. /**
  328. * 创建订单搜索商品
  329. * @throws \Exception
  330. */
  331. public function getGoodsByCondition()
  332. {
  333. $params = $this->request->getRawJson();
  334. $type = isset($params['type']) ? $params['type'] : false;
  335. $data['condition'] = isset($params['condition']) ? trim($params['condition']) : '';
  336. $data['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : 0;
  337. if (isset($this->shopId) && !empty($this->shopId)) $data['shopId'] = $this->shopId;
  338. $data['shopId'] = isset($params['shopId']) ? $params['shopId'] : [];
  339. $modelResult = $this->objMGoods->getGoodsByCondition($data, $type);
  340. if (!$modelResult->isSuccess()) {
  341. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  342. }
  343. parent::sendOutput($modelResult->getData());
  344. }
  345. /**
  346. * Doc: (des="es-商品搜索")
  347. * @example
  348. * 销售中 = 上架有库存
  349. * 已售罄 = 上下架没库存的
  350. * 仓库中 = 下架有库存
  351. * User: XMing
  352. * Date: 2020/11/30
  353. * Time: 10:43 上午
  354. * @throws \Exception
  355. */
  356. public function search()
  357. {
  358. $params = $this->request->getRawJson();
  359. if (empty($params)) {
  360. parent::sendOutput('参数为空', ErrorCode::$paramError);
  361. }
  362. $selectParams = [
  363. 'categoryPath' => isset($params['categoryPath']) ? $params['categoryPath'] : '',
  364. 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
  365. 'brandId' => isset($params['brandId']) ? $params['brandId'] : '',
  366. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  367. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',//销售状态
  368. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  369. ];
  370. //销售中 页面显示有库存,已上架,的商品。
  371. if (isset($params['inSales']) && !empty($params['inSales'])) {
  372. $selectParams['enableStatus'] = StatusCode::$standard;
  373. $selectParams['inStock'] = StatusCode::$standard;
  374. }
  375. //有无库存 inStock 5仓库中 4已售空
  376. if (isset($params['inStock']) && !empty($params['inStock'])) {
  377. if ($params['inStock'] == StatusCode::$standard) {
  378. //仓库中:有库存,未上架的商品列表
  379. $selectParams['enableStatus'] = StatusCode::$delete;
  380. $selectParams['inStock'] = $params['inStock'];
  381. } else {
  382. //已售罄:库存为0,自动下架的商品列表
  383. $selectParams['inStock'] = $params['inStock'];
  384. }
  385. }
  386. if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
  387. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  388. $selectParams['limit'] = $pageParams['limit'];
  389. $selectParams['offset'] = $pageParams['offset'];
  390. $is_export = false;
  391. if (isset($params['export']) && $params['export'] == 1) $is_export = true;
  392. $selectParams['auditStatus'] = StatusCode::$auditStatus['auditPass'];
  393. if (isset($params['auditStatus']) && !empty($params['auditStatus'])){
  394. $selectParams['auditStatus'] = $params['auditStatus'];
  395. }
  396. //ifMerchant (4 采购单 5商户入库单)
  397. if( isset($params['ifMerchant']) && !empty($params['ifMerchant']) ){
  398. $selectParams['ifMerchant'] = $params['ifMerchant'];
  399. }
  400. if( isset($params['merchantId']) && !empty($params['merchantId']) ){
  401. $selectParams['merchantId'] = $params['merchantId'];
  402. }
  403. $result = $this->objMGoods->search($selectParams, $is_export);
  404. if ($result->isSuccess()) {
  405. $returnData = $result->getData();
  406. $pageData = [
  407. 'pageIndex' => $params['page'],
  408. 'pageSize' => $params['pageSize'],
  409. 'pageTotal' => $returnData['total'],
  410. ];
  411. parent::sendOutput($returnData['data'], 0, $pageData);
  412. }
  413. parent::sendOutput($result->getData(), $result->getErrorCode());
  414. }
  415. //修补es数据
  416. public function fixEsData()
  417. {
  418. $params = $this->request->getRawJson();
  419. if (empty($params)) {
  420. $this->sendOutput('参数为空', ErrorCode::$paramError);
  421. }
  422. isset($params['id']) && $selectParams['id'] = $params['id'];
  423. $pageParams = pageToOffset(1, 4000);
  424. $selectParams['limit'] = $pageParams['limit'];
  425. $selectParams['offset'] = $pageParams['offset'];
  426. $this->objMGoods->fixEsData($selectParams);
  427. }
  428. /**
  429. *
  430. * @throws \Exception
  431. */
  432. public function getGoodsByBarCode()
  433. {
  434. $params = $this->request->getRawJson();
  435. if (empty($params['barCode'])) {
  436. $this->sendOutput('barCode参数为空', ErrorCode::$paramError);
  437. }
  438. $result = $this->objMGoods->getGoodsByBarCode($params['barCode']);
  439. if (!$result->isSuccess()) {
  440. parent::sendOutput($result->getData(), $result->getErrorCode());
  441. }
  442. parent::sendOutput($result->getData());
  443. }
  444. /**
  445. *
  446. * @throws \Exception
  447. */
  448. public function getAllGoodsBySku()
  449. {
  450. $params = $this->request->getRawJson();
  451. if (empty($params)) {
  452. parent::sendOutput('参数为空', ErrorCode::$paramError);
  453. }
  454. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  455. $data['limit'] = $pageParams['limit'];
  456. $data['offset'] = $pageParams['offset'];
  457. $data['keyword'] = isset($params['keyword']) ? $params['keyword'] : '';
  458. $data['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
  459. $data['categoryId'] = isset($params['categoryId']) ? $params['categoryId'] : '';
  460. $data['isRevealSku'] = getArrayItem($params,'isRevealSku','');
  461. if (isset($this->shopId) && !empty($this->shopId)) $data['shopId'] = $this->shopId;
  462. $data['userCenterId'] = getArrayItem($params,'userCenterId',0);
  463. $result = $this->objMGoods->getAllGoodsBySku($data);
  464. if ($result->isSuccess()) {
  465. $returnData = $result->getData();
  466. $pageData = [
  467. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  468. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  469. 'pageTotal' => $returnData['total'],
  470. ];
  471. parent::sendOutput($returnData['data'], 0, $pageData);
  472. }
  473. parent::sendOutput($result->getData(), $result->getErrorCode());
  474. }
  475. /**
  476. * 获取所有sku
  477. */
  478. public function getAllSku()
  479. {
  480. $params = $this->request->getRawJson();
  481. $result = $this->objMGoods->getAllSku($params);
  482. if(!$result->isSuccess()){
  483. parent::sendOutput($result->getData(),$result->getErrorCode());
  484. }
  485. parent::sendOutput($result->getData());
  486. }
  487. /**
  488. * Doc: (des="设置商品置顶/取消商品置顶")
  489. * User: XMing
  490. * Date: 2020/8/28
  491. * Time: 11:04 上午
  492. */
  493. public function setTop()
  494. {
  495. $goodsId = $this->request->param('request_id');
  496. if (empty($goodsId)) {
  497. parent::sendOutput('id参数错误', ErrorCode::$paramError);
  498. }
  499. $result = $this->objMGoods->setTop($goodsId);
  500. if (!$result->isSuccess()) {
  501. parent::sendOutput($result->getData(), $result->getErrorCode());
  502. }
  503. parent::sendOutput($result->getData());
  504. }
  505. /**
  506. * Doc: (des="修改排序字段")
  507. */
  508. public function setSort()
  509. {
  510. $params = $this->request->getRawJson();
  511. $params['id'] = getArrayItem($params,'id');
  512. $params['sort'] = getArrayItem($params,'sort',0);
  513. foreach ($params as $key => $value) {
  514. if (empty($value)) {
  515. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  516. }
  517. }
  518. $result = $this->objMGoods->setSort($params);
  519. if (!$result->isSuccess()) {
  520. parent::sendOutput($result->getData(), $result->getErrorCode());
  521. }
  522. parent::sendOutput($result->getData());
  523. }
  524. /**
  525. * Doc: (des="批量设置虚拟销量")
  526. * User: XMing
  527. * Date: 2020/9/3
  528. * Time: 9:10 上午
  529. * @throws \Exception
  530. */
  531. public function setSalesNumBatch()
  532. {
  533. $params = $this->request->getRawJson();
  534. $data = [
  535. 'ids' => isset($params['ids']) ? $params['ids'] : null,
  536. 'minVal' => isset($params['minVal']) ? $params['minVal'] : null,
  537. 'maxVal' => isset($params['maxVal']) ? $params['maxVal'] : null,
  538. ];
  539. foreach ($data as $key => $value) {
  540. if (empty($value) && $value != 0) {
  541. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  542. }
  543. }
  544. if ($data['minVal'] > $data['maxVal']) {
  545. parent::sendOutput('阀值设置有误', ErrorCode::$paramError);
  546. }
  547. $result = $this->objMGoods->setSalesNumBatch($data);
  548. if (!$result->isSuccess()) {
  549. parent::sendOutput($result->getData(), $result->getErrorCode());
  550. }
  551. parent::sendOutput($result->getData());
  552. }
  553. /**
  554. * Doc: (des="")
  555. * User: XMing
  556. * Date: 2020/9/10
  557. * Time: 3:07 下午
  558. */
  559. public function batchGoodsExpress()
  560. {
  561. $params = $this->request->getRawJson();
  562. $data = [
  563. 'ids' => isset($params['ids']) ? $params['ids'] : null,
  564. 'expressType' => isset($params['expressType']) ? $params['expressType'] : null,
  565. ];
  566. foreach ($data as $key => $value) {
  567. if (empty($value)) {
  568. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  569. }
  570. }
  571. if ($data['expressType'] == StatusCode::$expressType['rule']) {
  572. if (!isset($params['ruleId']) || empty($params['ruleId'])) {
  573. parent::sendOutput('ruleId参数错误', ErrorCode::$paramError);
  574. }
  575. $data['ruleId'] = $params['ruleId'];
  576. }
  577. if ($data['expressType'] == StatusCode::$expressType['unify']) {
  578. if (!isset($params['expressFee']) || (empty($params['expressFee']) && $params['expressFee'] != 0)) {
  579. parent::sendOutput('expressFee参数错误', ErrorCode::$paramError);
  580. }
  581. $data['expressFee'] = $params['expressFee'];
  582. }
  583. $result = $this->objMGoods->batchGoodsExpress($data);
  584. if (!$result->isSuccess()) {
  585. parent::sendOutput($result->getData(), $result->getErrorCode());
  586. }
  587. parent::sendOutput($result->getData());
  588. }
  589. /**
  590. * Doc: (des="批量设置运费")
  591. * User: XMing
  592. * Date: 2020/9/3
  593. * Time: 10:41 上午
  594. */
  595. public function setSalesNum()
  596. {
  597. $params = $this->request->getRawJson();
  598. $data = [
  599. 'id' => isset($params['id']) ? $params['id'] : null,
  600. 'val' => isset($params['val']) ? $params['val'] : null,
  601. ];
  602. foreach ($data as $key => $value) {
  603. if (empty($value) && $value != 0) {
  604. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  605. }
  606. }
  607. if ($data['minVal'] > $data['maxVal']) {
  608. parent::sendOutput('阀值设置有误', ErrorCode::$paramError);
  609. }
  610. $result = $this->objMGoods->setSalesNum($data);
  611. if (!$result->isSuccess()) {
  612. parent::sendOutput($result->getData(), $result->getErrorCode());
  613. }
  614. parent::sendOutput($result->getData());
  615. }
  616. /**
  617. * Doc: (des="根据基础物料id及店铺id,获取物料id对应商品id")
  618. * User: XMing
  619. * Date: 2020/12/25
  620. * Time: 3:57 下午
  621. */
  622. public function getRelMap()
  623. {
  624. $params = $this->request->getRawJson();
  625. $data = [
  626. 'shopId' => getArrayItem($params,'shopId',null),
  627. 'materielIds' => getArrayItem($params,'materielIds',null),
  628. ];
  629. foreach ($data as $key => $val){
  630. if (is_null($val) || empty($val)) {
  631. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  632. }
  633. }
  634. $result = $this->objMGoods->getRelMap($data);
  635. if (!$result->isSuccess()) {
  636. parent::sendOutput($result->getData(), $result->getErrorCode());
  637. }
  638. parent::sendOutput($result->getData());
  639. }
  640. /**
  641. * Doc: (des="获取价格走势")
  642. * User: XMing
  643. * Date: 2021/3/10
  644. * Time: 6:45 下午
  645. * @throws \Exception
  646. */
  647. public function getPriceTrend()
  648. {
  649. $goodsId = $this->request->param('request_id');
  650. if (empty($goodsId)) {
  651. parent::sendOutput('goodsId参数错误', ErrorCode::$paramError);
  652. }
  653. $params = (array)$this->request->getRawJson();
  654. $params['startTime'] = isset($params['startTime']) && !empty($params['startTime']) ? $params['startTime'] : strtotime(date('Y-m-d 00:00:00',strtotime('-10 day')));
  655. $params['endTime'] = isset($params['endTime']) && !empty($params['endTime']) ? $params['endTime'] :strtotime(date('Y-m-d 00:00:00'));
  656. $params['type'] = getArrayItem($params,'type',StatusCode::$standard);//5销售价格 4采购价格
  657. $result = $this->objMGoods->getPriceTrend($goodsId,$params);
  658. if (!$result->isSuccess()) {
  659. parent::sendOutput($result->getData(), $result->getErrorCode());
  660. }
  661. parent::sendOutput($result->getData());
  662. }
  663. /**
  664. * Doc: (des="批量设置负库存销售")
  665. * User: XMing
  666. * Date: 2021/3/13
  667. * Time: 10:11 上午
  668. */
  669. public function batchSetDistribution()
  670. {
  671. $params = $this->request->getRawJson();
  672. $data = [
  673. 'ids' => getArrayItem($params,'ids',null),
  674. 'isDistribution' => getArrayItem($params,'isDistribution',null),
  675. ];
  676. foreach ($data as $key => $val){
  677. if (is_null($val) || empty($val)) {
  678. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  679. }
  680. }
  681. $result = $this->objMGoods->batchSetDistribution($data);
  682. if (!$result->isSuccess()) {
  683. parent::sendOutput($result->getData(), $result->getErrorCode());
  684. }
  685. parent::sendOutput($result->getData());
  686. }
  687. }