PriceAdjustment.Class.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /**
  3. * 调价单管理
  4. * Created by PhpStorm.
  5. * User: xiaoming
  6. * Date: 2019/4/16
  7. * Time: 9:41 AM
  8. */
  9. namespace JinDouYun\Controller\Price;
  10. use Mall\Framework\Core\StatusCode;
  11. use Mall\Framework\Core\ErrorCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Price\MPriceAdjustment;
  14. class PriceAdjustment extends BaseController
  15. {
  16. private $objMPriceAdjustment;
  17. /**
  18. * PriceAdjustment constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. * @throws \Exception
  22. */
  23. public function __construct($isCheckAcl = true, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->objMPriceAdjustment = new MPriceAdjustment($this->onlineUserId, $this->onlineEnterpriseId);
  27. }
  28. /**
  29. * 公共接收参数方法
  30. * @return mixed
  31. */
  32. public function commonParams()
  33. {
  34. $params = $this->request->getRawJson();
  35. if (empty($params)) {
  36. $this->sendOutput('参数为空', ErrorCode::$paramError);
  37. }
  38. $sheetData = [];
  39. foreach ($params as $key => $value) {
  40. $sheetData[$key] = [
  41. 'createUserId' => $this->onlineUserId,
  42. 'createUserName' => isset($value['createUserName']) ? $value['createUserName'] : '',
  43. 'goodsName' => isset($value['goodsName']) ? $value['goodsName'] : '',
  44. 'goodsId' => isset($value['goodsId']) ? $value['goodsId'] : '',
  45. 'saleType' => isset($value['saleType']) ? $value['saleType'] : '', // 销售类型
  46. 'salePriceAreaType' => isset($value['salePriceAreaType']) ? $value['salePriceAreaType'] : '', // 销售价格生效区域类型
  47. 'salePriceType' => isset($value['salePriceType']) ? $value['salePriceType'] : '', // 价格类型
  48. 'salePrice' => isset($value['salePrice']) ? $value['salePrice'] : '', // 销售价
  49. 'shopId' => isset($value['shopId']) ? $value['shopId'] : '',
  50. 'shopName' => isset($value['shopName']) ? $value['shopName'] : '',
  51. 'createTime' => time(),
  52. 'updateTime' => time(),
  53. 'deleteStatus' => StatusCode::$standard,
  54. 'effectiveStatus' => StatusCode::$auditStatus['auditing'],
  55. ];
  56. foreach ($sheetData[$key] as $k => $v) {
  57. if (empty($v) && $v !== 0) {
  58. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  59. }
  60. }
  61. $sheetData[$key]['createTime'] = time();
  62. $sheetData[$key]['updateTime'] = time();
  63. $sheetData[$key]['goodsCode'] = createCode(StatusCode::$code['goodsBasic']['prefix'], $sheetData[$key]['goodsId'], StatusCode::$code['goodsBasic']['length']);
  64. $sheetData[$key]['salePrice'] = json_encode($sheetData[$key]['salePrice']);
  65. }
  66. return $sheetData;
  67. }
  68. /**
  69. * 新增调价单
  70. */
  71. public function add()
  72. {
  73. $sheetData = self::commonParams();
  74. $result = $this->objMPriceAdjustment->add($sheetData);
  75. if ($result->isSuccess()) {
  76. parent::sendOutput($result->getData());
  77. } else {
  78. parent::sendOutput($result->getData(), $result->getErrorCode());
  79. }
  80. }
  81. /**
  82. * 所有调价单列表
  83. */
  84. public function getAll()
  85. {
  86. $params['page'] = $this->request->param('page') ?: 1;
  87. $params['pageSize'] = $this->request->param('pageSize') ?: 10;
  88. $params['startTime'] = $this->request->param('startTime');
  89. $params['endTime'] = $this->request->param('endTime');
  90. $params['effectiveStatus'] = $this->request->param('effectiveStatus');
  91. $params['keyword'] = $this->request->param('keyword');
  92. $params['goodsId'] = $this->request->param('goodsId');
  93. $export = $this->request->param('export');
  94. if (isset($this->shopId) && !empty($this->shopId)) $params['shopId'] = $this->shopId;
  95. $result = $this->objMPriceAdjustment->getAll($params,$export);
  96. if ($result->isSuccess()) {
  97. $returnData = $result->getData();
  98. $pageData = [
  99. 'pageIndex' => $params['page'],
  100. 'pageSize' => $params['pageSize'],
  101. 'pageTotal' => $returnData['total'],
  102. ];
  103. parent::sendOutput($returnData['data'], 0, $pageData);
  104. } else {
  105. parent::sendOutput($result->getData(), $result->getErrorCode());
  106. }
  107. }
  108. /**
  109. * 生效操作
  110. * @throws \Exception
  111. */
  112. public function effective()
  113. {
  114. $id = $this->request->param('request_id');
  115. if (!$id) {
  116. parent::sendOutput('请指定要生效的数据id', ErrorCode::$paramError);
  117. }
  118. $paramsData = $this->request->getRawJson();
  119. $params = [
  120. 'createTime' => isset($paramsData['createTime']) ? $paramsData['createTime'] : '',
  121. 'effectiveUserName' => isset($paramsData['effectiveUserName']) ? $paramsData['effectiveUserName'] : '',
  122. 'effectiveUserId' => $this->onlineUserId,
  123. ];
  124. foreach ($params as $k => $v) {
  125. if (empty($v) && $v !== 0) {
  126. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  127. }
  128. }
  129. $result = $this->objMPriceAdjustment->effective($id, $params);
  130. if ($result->isSuccess()) {
  131. parent::sendOutput($result->getData());
  132. } else {
  133. parent::sendOutput($result->getData(), $result->getErrorCode());
  134. }
  135. }
  136. /**
  137. * 自动创建调价单且自动生效接口
  138. */
  139. public function addAndEffective()
  140. {
  141. $sheetData = self::commonParams();
  142. $result = $this->objMPriceAdjustment->addAndEffective($sheetData);
  143. if ($result->isSuccess()) {
  144. parent::sendOutput($result->getData());
  145. } else {
  146. parent::sendOutput($result->getData(), $result->getErrorCode());
  147. }
  148. }
  149. /**
  150. * 商品调价单搜索
  151. */
  152. public function search()
  153. {
  154. $params = $this->request->getRawJson();
  155. if (empty($params)) {
  156. $this->sendOutput('参数为空', ErrorCode::$paramError);
  157. }
  158. $selectParams = [
  159. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',//订单编号,收货人,商品名称
  160. 'startTime' => isset($params['startTime']) ? $params['startTime'] : '',//开始时间
  161. 'endTime' => isset($params['endTime']) ? $params['endTime'] : '',//结束时间
  162. 'effectiveStatus' => isset($params['effectiveStatus']) ? $params['effectiveStatus'] : '',//生效状态
  163. ];
  164. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  165. $selectParams['limit'] = $pageParams['limit'];
  166. $selectParams['offset'] = $pageParams['offset'];
  167. if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
  168. $result = $this->objMPriceAdjustment->search($selectParams);
  169. if ($result->isSuccess()) {
  170. $returnData = $result->getData();
  171. $pageData = [
  172. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  173. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  174. 'pageTotal' => $returnData['total'],
  175. ];
  176. parent::sendOutput($returnData['data'], 0, $pageData);
  177. } else {
  178. parent::sendOutput($result->getData(), $result->getErrorCode());
  179. }
  180. }
  181. }