CustomerPriceAdjustment.Class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. /**
  3. * 客户调价单管理
  4. * Created by PhpStorm.
  5. * User: phperstar
  6. * Date: 2019/4/26
  7. * Time: 9:41 AM
  8. */
  9. namespace JinDouYun\Controller\Price;
  10. use JinDouYun\Controller\BaseController;
  11. use Mall\Framework\Core\StatusCode;
  12. use Mall\Framework\Core\ErrorCode;
  13. use JinDouYun\Model\Price\MCustomerPriceAdjustment;
  14. class CustomerPriceAdjustment extends BaseController
  15. {
  16. private $objMCustomerPriceAdjustment;
  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->objMCustomerPriceAdjustment = new MCustomerPriceAdjustment($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. foreach ($params as $key => $value) {
  39. $sheetData[$key] = [
  40. 'createUserId' => $this->onlineUserId,
  41. 'createUserName' => isset($value['createUserName']) ? $value['createUserName'] : '',
  42. 'goodsName' => isset($value['goodsName']) ? $value['goodsName'] : '',
  43. 'goodsId' => isset($value['goodsId']) ? $value['goodsId'] : '',
  44. 'shopId' => isset($value['shopId']) ? $value['shopId'] : '',
  45. 'shopName' => isset($value['shopName']) ? $value['shopName'] : '',
  46. 'salePrice' => isset($value['salePrice']) ? $value['salePrice'] : '',
  47. 'createTime' => time(),
  48. 'updateTime' => time(),
  49. 'deleteStatus' => StatusCode::$standard,
  50. 'effectiveStatus' => StatusCode::$auditStatus['auditing'],
  51. 'customerName' => isset($value['customerName']) ? $value['customerName'] : '',
  52. 'customerId' => isset($value['customerId']) ? $value['customerId'] : '',
  53. ];
  54. foreach ($sheetData[$key] as $k => $v) {
  55. if (empty($v) && $v !== 0) {
  56. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  57. }
  58. }
  59. $sheetData[$key]['createTime'] = time();
  60. $sheetData[$key]['updateTime'] = time();
  61. $sheetData[$key]['startTime'] = isset($value['startTime']) ? $value['startTime'] : '';
  62. $sheetData[$key]['endTime'] = isset($value['endTime']) ? $value['endTime'] : '';
  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. $sheetData[$key]['effective'] = getArrayItem($value,'effective',StatusCode::$delete);
  66. }
  67. return $sheetData;
  68. }
  69. /**
  70. * 新增客户调价单
  71. *
  72. * @throws \Exception
  73. */
  74. public function add()
  75. {
  76. $sheetData = self::commonParams();
  77. $result = $this->objMCustomerPriceAdjustment->add($sheetData);
  78. if ($result->isSuccess()) {
  79. //调价单生效操作
  80. $sheetIds = $result->getData();
  81. foreach ($sheetIds as $key => $id){
  82. $row = getArrayItem($sheetData,$key,[]);
  83. if($row['effective'] == StatusCode::$standard){
  84. $effectiveResult = $this->objMCustomerPriceAdjustment->effective($id,$row);
  85. if (!$effectiveResult->isSuccess()){
  86. parent::sendOutput($effectiveResult->getData());
  87. }
  88. }
  89. }
  90. parent::sendOutput($result->getData());
  91. }
  92. parent::sendOutput($result->getData(), $result->getErrorCode());
  93. }
  94. /**
  95. * 获取指定用户区域可售商品
  96. */
  97. public function goodsLists()
  98. {
  99. $params['provinceId'] = $this->request->param('provinceId');
  100. $params['cityId'] = $this->request->param('cityId');
  101. $params['districtId'] = $this->request->param('districtId');
  102. $params['shopId'] = $this->request->param('shopId');
  103. $params['page'] = $this->request->param('page');
  104. $params['pageSize'] = $this->request->param('pageSize');
  105. foreach ($params as $k => $v) {
  106. if (empty($v) && $v !== 0) {
  107. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  108. }
  109. }
  110. $params['keyword'] = $this->request->param('keyword') ?: '';
  111. $result = $this->objMCustomerPriceAdjustment->goodsLists($params);
  112. if ($result->isSuccess()) {
  113. $returnData = $result->getData();
  114. $pageData = [
  115. 'pageIndex' => $params['page'],
  116. 'pageSize' => $params['pageSize'],
  117. 'pageTotal' => $returnData['total'],
  118. ];
  119. parent::sendOutput($returnData['data'], 0, $pageData);
  120. } else {
  121. parent::sendOutput($result->getData(), $result->getErrorCode());
  122. }
  123. }
  124. /**
  125. * 所有调价单列表
  126. */
  127. public function getAll()
  128. {
  129. $params['page'] = $this->request->param('page') ?: 1;
  130. $params['pageSize'] = $this->request->param('pageSize') ?: 10;
  131. $params['startTime'] = $this->request->param('startTime');
  132. $params['endTime'] = $this->request->param('endTime');
  133. $params['effectiveStatus'] = $this->request->param('effectiveStatus');
  134. $params['keyword'] = $this->request->param('keyword');
  135. $params['goodsId'] = $this->request->param('goodsId');
  136. $export = $this->request->param('export');
  137. if (isset($this->shopId) && !empty($this->shopId)) $params['shopId'] = $this->shopId;
  138. $result = $this->objMCustomerPriceAdjustment->getAll($params,$export);
  139. if ($result->isSuccess()) {
  140. $returnData = $result->getData();
  141. $pageData = [
  142. 'pageIndex' => $params['page'],
  143. 'pageSize' => $params['pageSize'],
  144. 'pageTotal' => $returnData['total'],
  145. ];
  146. parent::sendOutput($returnData['data'], 0, $pageData);
  147. } else {
  148. parent::sendOutput($result->getData(), $result->getErrorCode());
  149. }
  150. }
  151. /**
  152. * 生效操作
  153. * @throws \Exception
  154. */
  155. public function effective()
  156. {
  157. $id = $this->request->param('request_id');
  158. if (!$id) {
  159. parent::sendOutput('请指定要生效的数据id', ErrorCode::$paramError);
  160. }
  161. $paramsData=$this->request->getRawJson();
  162. $params=[
  163. 'createTime'=>isset($paramsData['createTime']) ? $paramsData['createTime']: '',
  164. 'effectiveUserName'=>isset($paramsData['effectiveUserName']) ? $paramsData['effectiveUserName']: '',
  165. 'effectiveUserId'=>$this->onlineUserId,
  166. ];
  167. foreach ($params as $k => $v) {
  168. if (empty($v) && $v !== 0) {
  169. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  170. }
  171. }
  172. $result = $this->objMCustomerPriceAdjustment->effective($id,$params);
  173. if ($result->isSuccess()) {
  174. parent::sendOutput($result->getData());
  175. } else {
  176. parent::sendOutput($result->getData(), $result->getErrorCode());
  177. }
  178. }
  179. /**
  180. * 客户调价单搜索
  181. */
  182. public function search()
  183. {
  184. $params = $this->request->getRawJson();
  185. if (empty($params)) {
  186. $this->sendOutput('参数为空', ErrorCode::$paramError);
  187. }
  188. $selectParams = [
  189. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',//订单编号,收货人,商品名称
  190. 'startTime' => isset($params['startTime']) ? $params['startTime'] : '',//开始时间
  191. 'endTime' => isset($params['endTime']) ? $params['endTime'] : '',//结束时间
  192. 'effectiveStatus' => isset($params['effectiveStatus']) ? $params['effectiveStatus'] : '',//生效状态
  193. ];
  194. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  195. $selectParams['limit'] = $pageParams['limit'];
  196. $selectParams['offset'] = $pageParams['offset'];
  197. $result = $this->objMCustomerPriceAdjustment->search($selectParams);
  198. if ($result->isSuccess()) {
  199. $returnData = $result->getData();
  200. $pageData = [
  201. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  202. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  203. 'pageTotal' => $returnData['total'],
  204. ];
  205. parent::sendOutput($returnData['data'], 0, $pageData);
  206. } else {
  207. parent::sendOutput($result->getData(), $result->getErrorCode());
  208. }
  209. }
  210. /**
  211. * 获取指定商品的最后生效的客户调价单数据
  212. */
  213. public function getCustomerPriceByGoodsIds()
  214. {
  215. $params['page'] = $this->request->param('page') ?: 1;
  216. $params['pageSize'] = $this->request->param('pageSize') ?: 10;
  217. $params['goodsId'] = $this->request->param('goodsId');
  218. $result = $this->objMCustomerPriceAdjustment->getCustomerPriceByGoodsIds($params);
  219. if ($result->isSuccess()) {
  220. $returnData = $result->getData();
  221. $pageData = [
  222. 'pageIndex' => $params['page'],
  223. 'pageSize' => $params['pageSize'],
  224. 'pageTotal' => $returnData['total'],
  225. ];
  226. parent::sendOutput($returnData['data'], 0, $pageData);
  227. } else {
  228. parent::sendOutput($result->getData(), $result->getErrorCode());
  229. }
  230. }
  231. /**
  232. * 删除指定商品的最后生效的客户调价单数据
  233. */
  234. public function delCustomerPrice()
  235. {
  236. $paramsDate = $this->request->getRawJson();
  237. $params['id'] = $paramsDate['id'];
  238. $params['skuId'] = $paramsDate['skuId'];
  239. foreach ($params as $k => $v) {
  240. if (empty($v) && $v !== 0) {
  241. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  242. }
  243. }
  244. $result = $this->objMCustomerPriceAdjustment->delCustomerPrice($params);
  245. if($result->isSuccess()){
  246. parent::sendOutput($result->getData());
  247. }else{
  248. parent::sendOutput($result->getData(), $result->getErrorCode());
  249. }
  250. }
  251. }