CustomerTypePriceAdjustment.Class.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * 客户类型调价单
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2020/4/8
  7. * Time: 17:56
  8. */
  9. namespace JinDouYun\Controller\Price;
  10. use JinDouYun\Controller\BaseController;
  11. use JinDouYun\Model\Price\MCustomerTypePriceAdjustment;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\StatusCode;
  14. class CustomerTypePriceAdjustment extends BaseController
  15. {
  16. private $objMCustomerTypePriceAdjustment;
  17. /**
  18. * CustomerPriceAdjustment 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->objMCustomerTypePriceAdjustment = new MCustomerTypePriceAdjustment($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. 'shopId' => isset($value['shopId']) ? $value['shopId'] : '',
  46. 'shopName' => isset($value['shopName']) ? $value['shopName'] : '',
  47. 'salePrice' => isset($value['salePrice']) ? $value['salePrice'] : '',
  48. 'createTime' => time(),
  49. 'updateTime' => time(),
  50. 'deleteStatus' => StatusCode::$standard,
  51. 'effectiveStatus' => StatusCode::$auditStatus['auditing'],
  52. 'customerName' => isset($value['customerName']) ? $value['customerName'] : '',
  53. 'customerType' => isset($value['customerType']) ? $value['customerType'] : '',
  54. ];
  55. foreach ($sheetData[$key] as $k => $v) {
  56. if (empty($v) && $v !== 0) {
  57. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  58. }
  59. }
  60. $sheetData[$key]['createTime'] = time();
  61. $sheetData[$key]['updateTime'] = time();
  62. $sheetData[$key]['startTime'] = isset($value['startTime']) ? $value['startTime'] : '';
  63. $sheetData[$key]['endTime'] = isset($value['endTime']) ? $value['endTime'] : '';
  64. $sheetData[$key]['goodsCode'] = createCode(StatusCode::$code['goodsBasic']['prefix'], $sheetData[$key]['goodsId'], StatusCode::$code['goodsBasic']['length']);
  65. $sheetData[$key]['salePrice'] = json_encode($sheetData[$key]['salePrice']);
  66. $sheetData[$key]['effective'] = getArrayItem($value,'effective',StatusCode::$delete);
  67. }
  68. return $sheetData;
  69. }
  70. /**
  71. * 新增客户调价单
  72. *
  73. * @throws \Exception
  74. */
  75. public function add()
  76. {
  77. $sheetData = self::commonParams();
  78. $result = $this->objMCustomerTypePriceAdjustment->add($sheetData);
  79. if ($result->isSuccess()) {
  80. //调价单生效操作
  81. $sheetIds = $result->getData();
  82. foreach ($sheetIds as $key => $id){
  83. $row = getArrayItem($sheetData,$key,[]);
  84. if($row['effective'] == StatusCode::$standard){
  85. $effectiveResult = $this->objMCustomerTypePriceAdjustment->effective($id,$row);
  86. if (!$effectiveResult->isSuccess()){
  87. parent::sendOutput($effectiveResult->getData());
  88. }
  89. }
  90. }
  91. parent::sendOutput($result->getData());
  92. }
  93. parent::sendOutput($result->getData(), $result->getErrorCode());
  94. }
  95. /**
  96. * 类型调价单列表
  97. */
  98. public function getAll()
  99. {
  100. $params['page'] = $this->request->param('page') ?: 1;
  101. $params['pageSize'] = $this->request->param('pageSize') ?: 10;
  102. $params['startTime'] = $this->request->param('startTime');
  103. $params['endTime'] = $this->request->param('endTime');
  104. $params['effectiveStatus'] = $this->request->param('effectiveStatus');
  105. $params['keyword'] = $this->request->param('keyword');
  106. $params['goodsId'] = $this->request->param('goodsId');
  107. $export = $this->request->param('export');
  108. if (isset($this->shopId) && !empty($this->shopId)) $params['shopId'] = $this->shopId;
  109. $result = $this->objMCustomerTypePriceAdjustment->getAll($params,$export);
  110. if ($result->isSuccess()) {
  111. $returnData = $result->getData();
  112. $pageData = [
  113. 'pageIndex' => $params['page'],
  114. 'pageSize' => $params['pageSize'],
  115. 'pageTotal' => $returnData['total'],
  116. ];
  117. parent::sendOutput($returnData['data'], 0, $pageData);
  118. } else {
  119. parent::sendOutput($result->getData(), $result->getErrorCode());
  120. }
  121. }
  122. /**
  123. * 生效操作
  124. * @throws \Exception
  125. */
  126. public function effective()
  127. {
  128. $id = $this->request->param('request_id');
  129. if (!$id) {
  130. parent::sendOutput('请指定要生效的数据id', ErrorCode::$paramError);
  131. }
  132. $paramsData = $this->request->getRawJson();
  133. $params = [
  134. 'createTime' => isset($paramsData['createTime']) ? $paramsData['createTime'] : '',
  135. 'effectiveUserName' => isset($paramsData['effectiveUserName']) ? $paramsData['effectiveUserName'] : '',
  136. 'effectiveUserId' => $this->onlineUserId,
  137. ];
  138. foreach ($params as $k => $v) {
  139. if (empty($v) && $v !== 0) {
  140. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  141. }
  142. }
  143. $result = $this->objMCustomerTypePriceAdjustment->effective($id, $params);
  144. if ($result->isSuccess()) {
  145. parent::sendOutput($result->getData());
  146. } else {
  147. parent::sendOutput($result->getData(), $result->getErrorCode());
  148. }
  149. }
  150. /**
  151. * 获取指定商品的最后生效的客户类型调价数据
  152. */
  153. public function getCustomerTypePriceByGoodsIds()
  154. {
  155. $params['page'] = $this->request->param('page') ?: 1;
  156. $params['pageSize'] = $this->request->param('pageSize') ?: 10;
  157. $params['goodsId'] = $this->request->param('goodsId');
  158. $result = $this->objMCustomerTypePriceAdjustment->getCustomerTypePriceByGoodsIds($params);
  159. if ($result->isSuccess()) {
  160. $returnData = $result->getData();
  161. $pageData = [
  162. 'pageIndex' => $params['page'],
  163. 'pageSize' => $params['pageSize'],
  164. 'pageTotal' => $returnData['total'],
  165. ];
  166. parent::sendOutput($returnData['data'], 0, $pageData);
  167. } else {
  168. parent::sendOutput($result->getData(), $result->getErrorCode());
  169. }
  170. }
  171. /**
  172. * 删除指定商品的最后生效的客户类型调价数据
  173. */
  174. public function delCustomerTypePrice()
  175. {
  176. $paramsDate = $this->request->getRawJson();
  177. $params['id'] = $paramsDate['id'];
  178. $params['skuId'] = $paramsDate['skuId'];
  179. foreach ($params as $k => $v) {
  180. if (empty($v) && $v !== 0) {
  181. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  182. }
  183. }
  184. $result = $this->objMCustomerTypePriceAdjustment->delCustomerTypePrice($params);
  185. if($result->isSuccess()){
  186. parent::sendOutput($result->getData());
  187. }else{
  188. parent::sendOutput($result->getData(), $result->getErrorCode());
  189. }
  190. }
  191. }