Price.Class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * 对外获取价格
  4. * Created by PhpStorm.
  5. * User: phperstar
  6. * Date: 2019/5/7
  7. * Time: 6:41 PM
  8. */
  9. namespace JinDouYun\Controller\Price;
  10. use JinDouYun\Controller\BaseController;
  11. use JinDouYun\Model\Goods\MGoods;
  12. use Mall\Framework\Core\ErrorCode;
  13. use JinDouYun\Model\Price\MPrice;
  14. class Price extends BaseController
  15. {
  16. private $objMPrice;
  17. /**
  18. * Price 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->objMPrice = new MPrice($this->onlineUserId, $this->onlineEnterpriseId);
  27. }
  28. /**
  29. * 批量调价基于基本的运算公式进行调价,举例一个商品的销售价格是100元。通过批量调价,订货价=销售价-1,那么结果就是 98(订货价)=99(销售价 salePrice)-1(调价数字)
  30. * 一个商品多个规格,每个规格都按照此调价数字进行调价
  31. * @throws \Exception
  32. */
  33. public function batchPrice()
  34. {
  35. $paramsData = $this->request->getRawJson();
  36. $params = [
  37. 'rows' => isset($paramsData['rows']) ? $paramsData['rows'] : '',
  38. 'sales' => isset($paramsData['sales']) ? $paramsData['sales'] : '',
  39. 'ladder' => isset($paramsData['ladder']) ? $paramsData['ladder'] : '',
  40. ];
  41. foreach ($params as $k => $v) {
  42. if (empty($v) && $v !== 0) {
  43. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  44. }
  45. }
  46. $goodData = [];
  47. foreach ($paramsData['rows'] as $key => $val) {
  48. $goodData[$key] = [
  49. 'goodsId' => isset($val['goodsId']) ? $val['goodsId'] : '',
  50. 'shopId' => isset($val['shopId']) ? $val['shopId'] : '',
  51. ];
  52. foreach ($goodData[$key] as $k => $v) {
  53. if (empty($v) && $v !== 0) {
  54. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  55. }
  56. }
  57. }
  58. $params['rows'] = $goodData;
  59. if (!isset($params['sales']['adj']) || !isset($params['sales']['float'])) {
  60. parent::sendOutput('sales参数错误', ErrorCode::$paramError);
  61. }
  62. if (!isset($params['ladder']['adj']) || !isset($params['ladder']['float'])) {
  63. parent::sendOutput('ladder参数错误', ErrorCode::$paramError);
  64. }
  65. $result = $this->objMPrice->batchPrice($params);
  66. if ($result->isSuccess()) {
  67. parent::sendOutput($result->getData());
  68. }
  69. parent::sendOutput($result->getData(), $result->getErrorCode());
  70. }
  71. /**
  72. * 根据用户定位批量获取指定物料价格
  73. * @throws \Exception
  74. */
  75. public function getPrice()
  76. {
  77. $paramsData = $this->request->getRawJson();
  78. $params = [
  79. 'material' => isset($paramsData['material']) ? $paramsData['material'] : '',
  80. 'province' => isset($paramsData['province']) ? $paramsData['province'] : '',
  81. 'city' => isset($paramsData['city']) ? $paramsData['city'] : '',
  82. 'district' => isset($paramsData['district']) ? $paramsData['district'] : '',
  83. ];
  84. foreach ($params as $k => $v) {
  85. if (empty($v) && $v !== 0) {
  86. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  87. }
  88. }
  89. $params['customerId'] = isset($paramsData['customerId']) ? $paramsData['customerId'] : '';
  90. $result = $this->objMPrice->getPrice($params);
  91. if ($result->isSuccess()) {
  92. parent::sendOutput($result->getData());
  93. } else {
  94. parent::sendOutput($result->getData(), $result->getErrorCode());
  95. }
  96. }
  97. /**
  98. * @throws \Exception
  99. */
  100. public function getAllGoodsPrice()
  101. {
  102. $params = $this->request->getRawJson();
  103. $paramsData = [
  104. 'page' => isset($params['page']) ? $params['page'] : 1,
  105. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  106. ];
  107. if (empty($params)) {
  108. $this->sendOutput('参数为空', ErrorCode::$paramError);
  109. }
  110. $pageParams = pageToOffset($paramsData['page'], $paramsData['pageSize']);
  111. $selectParams['limit'] = $pageParams['limit'];
  112. $selectParams['offset'] = $pageParams['offset'];
  113. if (isset($params['shopId']) && !empty($params['shopId'])) {
  114. $selectParams['shopId'] = $params['shopId'];
  115. }
  116. if (isset($params['merchantId']) && !empty($params['merchantId'])) {
  117. $selectParams['merchantId'] = $params['merchantId'];
  118. }
  119. if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
  120. $result = $this->objMPrice->getAllGoodsPrice($selectParams);
  121. if ($result->isSuccess()) {
  122. $returnData = $result->getData();
  123. $pageData = [
  124. 'pageIndex' => $paramsData['page'],
  125. 'pageSize' => $paramsData['pageSize'],
  126. 'pageTotal' => $returnData['total'],
  127. ];
  128. parent::sendOutput($returnData['data'], 0, $pageData);
  129. } else {
  130. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  131. }
  132. }
  133. /**
  134. * 价格管理搜索
  135. * @throws \Exception
  136. */
  137. public function search()
  138. {
  139. $params = $this->request->getRawJson();
  140. if (empty($params)) {
  141. $this->sendOutput('参数为空', ErrorCode::$paramError);
  142. }
  143. $selectParams = [
  144. 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
  145. 'brandId' => isset($params['brandId']) ? $params['brandId'] : '',
  146. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  147. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',//销售状态
  148. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  149. ];
  150. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  151. $selectParams['limit'] = $pageParams['limit'];
  152. $selectParams['offset'] = $pageParams['offset'];
  153. if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
  154. $result = $this->objMPrice->search($selectParams);
  155. if ($result->isSuccess()) {
  156. $returnData = $result->getData();
  157. $pageData = [
  158. 'pageIndex' => $params['page'],
  159. 'pageSize' => $params['pageSize'],
  160. 'pageTotal' => $returnData['total'],
  161. ];
  162. parent::sendOutput($returnData['data'], 0, $pageData);
  163. } else {
  164. parent::sendOutput($result->getData(), $result->getErrorCode());
  165. }
  166. }
  167. /**
  168. * 价格表列表页
  169. */
  170. public function getAll()
  171. {
  172. $params = $this->request->getRawJson();
  173. $params = [
  174. 'regionalDepartmentId' => $params['regionalDepartmentId'],
  175. 'materialData' => $params['materialData'],
  176. 'shopId' => $params['shopId'],
  177. 'cargoOwnerType' => $params['cargoOwnerType'],
  178. 'cargoOwnerCode' => $params['cargoOwnerCode'],
  179. ];
  180. foreach ($params as $k => $v) {
  181. if (empty($v) && $v !== 0) {
  182. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  183. }
  184. }
  185. $result = $this->objMPrice->getAll($params, $this->authorization);
  186. if ($result->isSuccess()) {
  187. parent::sendOutput($result->getData());
  188. } else {
  189. parent::sendOutput($result->getData(), $result->getErrorCode());
  190. }
  191. }
  192. /**
  193. *
  194. */
  195. public function searchGoods()
  196. {
  197. $params = $this->request->getRawJson();
  198. if (empty($params)) {
  199. $this->sendOutput('参数为空', ErrorCode::$paramError);
  200. }
  201. $selectParams = [
  202. 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
  203. 'brandId' => isset($params['brandId']) ? $params['brandId'] : '',
  204. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  205. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',//销售状态
  206. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  207. ];
  208. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  209. $selectParams['limit'] = $pageParams['limit'];
  210. $selectParams['offset'] = $pageParams['offset'];
  211. $result = $this->objMPrice->search($selectParams);
  212. if($result->isSuccess()){
  213. $returnData = $result->getData();
  214. $pageData = [
  215. 'pageIndex' => $params['page'],
  216. 'pageSize' => $params['pageSize'],
  217. 'pageTotal' => $returnData['total'],
  218. ];
  219. parent::sendOutput($returnData['data'], 0, $pageData);
  220. }
  221. parent::sendOutput($result->getData(), $result->getErrorCode());
  222. }
  223. /**
  224. * 获取指定店铺下指定物料的大区以及市价格(包含没有设置价格的区域)
  225. */
  226. public function getAreaPriceByMaterialCode()
  227. {
  228. $params = [
  229. 'marketCode' => $this->request->param('marketCode'),
  230. 'materialCode' => $this->request->param('materialCode'),
  231. 'shopId' => $this->request->param('shopId'),
  232. 'cargoOwnerCode' => $this->request->param('cargoOwnerCode'),
  233. 'weight' => $this->request->param('weight'),
  234. ];
  235. foreach ($params as $k => $v) {
  236. if (empty($v) && $v !== 0) {
  237. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  238. }
  239. }
  240. $result = $this->objMPrice->getAreaPriceByMaterialCode($params, $this->authorization);
  241. if ($result->isSuccess()) {
  242. parent::sendOutput($result->getData());
  243. } else {
  244. parent::sendOutput($result->getData(), $result->getErrorCode());
  245. }
  246. }
  247. /**
  248. * 获取指定店铺指定物料的设置过得全国销售价和库存数量
  249. */
  250. public function getNationalUnifiedPriceAndStock()
  251. {
  252. $params = [
  253. 'marketCode' => $this->request->param('marketCode'),
  254. 'materialCode' => $this->request->param('materialCode'),
  255. 'shopId' => $this->request->param('shopId'),
  256. 'cargoOwnerCode' => $this->request->param('cargoOwnerCode'),
  257. 'weight' => $this->request->param('weight'),
  258. ];
  259. foreach ($params as $k => $v) {
  260. if (empty($v) && $v !== 0) {
  261. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  262. }
  263. }
  264. $result = $this->objMPrice->getNationalUnifiedPriceAndStock($params, $this->authorization);
  265. if ($result->isSuccess()) {
  266. parent::sendOutput($result->getData());
  267. } else {
  268. parent::sendOutput($result->getData(), $result->getErrorCode());
  269. }
  270. }
  271. /**
  272. * 获取指定物料指定店铺当前设置过的所有区域价格(只返回设置过价格的区域)
  273. */
  274. public function getAreaPrice()
  275. {
  276. $params = [
  277. 'marketCode' => $this->request->param('marketCode'),
  278. 'materialCode' => $this->request->param('materialCode'),
  279. 'shopId' => $this->request->param('shopId'),
  280. ];
  281. foreach ($params as $k => $v) {
  282. if (empty($v) && $v !== 0) {
  283. $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
  284. }
  285. }
  286. $newParams = [
  287. $params['shopId'] => [$params['marketCode']]
  288. ];
  289. $result = $this->objMPrice->getAllAreaPrice($newParams, $params);
  290. if ($result->isSuccess()) {
  291. $areaPice = $result->getData();
  292. $returnData = (isset($areaPice[$params['shopId']][$params['marketCode']]) && !empty($areaPice[$params['shopId']][$params['marketCode']])) ? $areaPice[$params['shopId']][$params['marketCode']] : (object)[];
  293. parent::sendOutput($returnData);
  294. } else {
  295. parent::sendOutput($result->getData(), $result->getErrorCode());
  296. }
  297. }
  298. }