Warehouse.Class.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /**
  3. * 仓库管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/11/09
  7. * Time: 15:00
  8. */
  9. namespace JinDouYun\Controller\Stock;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\Stock\MWarehouse;
  15. class Warehouse extends BaseController
  16. {
  17. private $objMWarehouse;
  18. private $enterpriseId;
  19. public function __construct($isCheckAcl = true, $isMustLogin = true)
  20. {
  21. parent::__construct($isCheckAcl, $isMustLogin);
  22. $this->objMWarehouse = new MWarehouse($this->onlineEnterpriseId, $this->onlineUserId);
  23. }
  24. /**
  25. * 获取参数
  26. *
  27. * @return array
  28. */
  29. public function commonFieldFilter()
  30. {
  31. $params = $this->request->getRawJson();
  32. if (empty($params)) {
  33. $this->sendOutput('参数为空', ErrorCode::$paramError);
  34. }
  35. $WarehouseData = [
  36. "warehouseName" => isset($params['warehouseName']) ? $params['warehouseName'] : '', //varchar(255) DEFAULT NULL COMMENT '仓库名称',
  37. ];
  38. //必填项
  39. foreach ($WarehouseData as $key => $value) {
  40. if (empty($value) && $value !== 0) {
  41. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  42. }
  43. }
  44. //选填项
  45. $WarehouseData['updateTime'] = time();
  46. $WarehouseData['contactName'] = isset($params['contactName']) ? $params['contactName'] : '';
  47. $WarehouseData['contactMobile'] = isset($params['contactMobile']) ? $params['contactMobile'] : '';
  48. $WarehouseData['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
  49. $WarehouseData['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
  50. $WarehouseData['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
  51. $WarehouseData['contactAddress'] = isset($params['contactAddress']) ? $params['contactAddress'] : '';
  52. $WarehouseData['costType'] = isset($params['costType']) ? $params['costType'] : 1;
  53. $WarehouseData['deleteStatus'] = isset($params['deleteStatus']) ? $params['deleteStatus'] : StatusCode::$standard;
  54. $WarehouseData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$standard;
  55. $WarehouseData['remarks'] = isset($params['remarks']) ? $params['remarks'] : '';
  56. return $WarehouseData;
  57. }
  58. /**
  59. * 增
  60. */
  61. /**
  62. * 仓库添加
  63. * @throws Exception
  64. */
  65. public function addWarehouse()
  66. {
  67. $WarehouseData = $this->commonFieldFilter();
  68. $result = $this->objMWarehouse->addWarehouse($WarehouseData);
  69. if ($result->isSuccess()) {
  70. parent::sendOutput($result->getData());
  71. } else {
  72. parent::sendOutput($result->getData(), $result->getErrorCode());
  73. }
  74. }
  75. /**
  76. * 仓库期初添加
  77. * @throws Exception
  78. */
  79. public function addWarehouseBeginning()
  80. {
  81. $params = $this->request->getRawJson();
  82. if(empty($params)){
  83. parent::sendOutput('参数为空', ErrorCode::$paramError);
  84. }
  85. $addData = [
  86. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  87. 'operatorId' => $this->onlineUserId,
  88. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  89. 'paramsMaterielData' => isset($params['paramsMaterielData']) ? $params['paramsMaterielData'] : [],
  90. ];
  91. foreach($addData as $key => $value){
  92. if(empty($value)){
  93. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  94. }
  95. }
  96. $addData['remark'] = isset($params['remark']) ? $params['remark'] : '';
  97. $addMaterielData = [];
  98. foreach($addData['paramsMaterielData'] as $key => $value){
  99. $details = [
  100. 'warehouseId' => isset($addData['warehouseId']) ? $addData['warehouseId'] : '',
  101. 'operatorId' => isset($addData['operatorId']) ? $addData['operatorId'] : '',
  102. 'operatorName' => isset($addData['operatorName']) ? $addData['operatorName'] : '',
  103. 'materielId' => isset($value['materielId']) ? $value['materielId'] : '',
  104. 'materielName' => isset($value['materielName']) ? $value['materielName'] : '',
  105. 'materielCode' => isset($value['materielCode']) ? $value['materielCode'] : '',
  106. 'skuId' => isset($value['skuId']) ? $value['skuId'] : '',
  107. 'num' => isset($value['num']) ? $value['num'] : '',
  108. 'costPrice' => isset($value['costPrice']) ? $value['costPrice'] : '',
  109. 'updateTime' => time(),
  110. 'createTime' => time(),
  111. ];
  112. foreach($details as $k => $v){
  113. if(empty($v)){
  114. parent::sendOutput($k.'参数错误', ErrorCode::$paramError);
  115. }
  116. }
  117. $details['remark'] = isset($addData['remark']) ? $addData['remark'] : '';
  118. $addMaterielData[] = $details;
  119. }
  120. $result = $this->objMWarehouse->addWarehouseBeginning($addMaterielData);
  121. if ($result->isSuccess()) {
  122. parent::sendOutput($result->getData());
  123. } else {
  124. parent::sendOutput($result->getData(), $result->getErrorCode());
  125. }
  126. }
  127. /**
  128. * 删
  129. */
  130. /**
  131. * 仓库删除
  132. */
  133. public function deleteWarehouse()
  134. {
  135. $params['id'] = $this->request->param('request_id');
  136. if (empty($params)) {
  137. $this->sendOutput('参数为空', ErrorCode::$paramError);
  138. }
  139. $result = $this->objMWarehouse->deleteWarehouse($params);
  140. if ($result->isSuccess()) {
  141. parent::sendOutput($result->getData());
  142. } else {
  143. parent::sendOutput($result->getData(), $result->getErrorCode());
  144. }
  145. }
  146. /**
  147. * 改
  148. */
  149. /**
  150. * 仓库修改
  151. */
  152. public function updateWarehouse()
  153. {
  154. $params['id'] = $this->request->param('request_id');
  155. if (empty($params)) {
  156. $this->sendOutput('参数为空', ErrorCode::$paramError);
  157. }
  158. $WarehouseData = $this->commonFieldFilter();
  159. $result = $this->objMWarehouse->updateWarehouse($WarehouseData, $params);
  160. if ($result->isSuccess()) {
  161. parent::sendOutput($result->getData());
  162. } else {
  163. parent::sendOutput($result->getData(), $result->getErrorCode());
  164. }
  165. }
  166. /**
  167. * 仓库启用/禁用
  168. */
  169. public function enableWarehouse()
  170. {
  171. $paramsData = $this->request->getRawJson();
  172. if (empty($paramsData)) {
  173. $this->sendOutput('参数为空', ErrorCode::$paramError);
  174. }
  175. $params = [
  176. 'id' => isset($paramsData['id']) ? $paramsData['id'] : '',
  177. 'enableStatus' => isset($paramsData['enableStatus']) ? $paramsData['enableStatus'] : '',
  178. ];
  179. foreach ($params as $key => $value) {
  180. if (empty($value) && $value !== 0) {
  181. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  182. }
  183. }
  184. if ($params['enableStatus'] != StatusCode::$standard && $params['enableStatus'] != StatusCode::$delete) {
  185. $this->sendOutput('enableStatus参数错误', ErrorCode::$paramError);
  186. }
  187. $result = $this->objMWarehouse->enableWarehouse($params);
  188. if ($result->isSuccess()) {
  189. parent::sendOutput($result->getData());
  190. } else {
  191. parent::sendOutput($result->getData(), $result->getErrorCode());
  192. }
  193. }
  194. /**
  195. * 查
  196. */
  197. /**
  198. * 仓库列表
  199. */
  200. public function getAllWarehouse()
  201. {
  202. $params = $this->request->getRawJson();
  203. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  204. $selectParams['limit'] = $pageParams['limit'];
  205. $selectParams['offset'] = $pageParams['offset'];
  206. isset($params['notId']) && $selectParams['id'] = $params['notId'];
  207. isset($params['enableStatus']) && $selectParams['enableStatus'] = $params['enableStatus'];
  208. if(!empty($this->shopId)){
  209. $selectParams['shopId'] = $this->shopId;
  210. }
  211. $result = $this->objMWarehouse->getAllWarehouse($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. } else {
  221. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  222. }
  223. }
  224. /**
  225. * 仓库详情
  226. */
  227. public function getWarehouseInfo()
  228. {
  229. $params['id'] = $this->request->param('request_id');
  230. if (empty($params['id'])) {
  231. $this->sendOutput('参数为空', ErrorCode::$paramError);
  232. }
  233. $result = $this->objMWarehouse->getWarehouseInfo($params);
  234. if ($result->isSuccess()) {
  235. parent::sendOutput($result->getData());
  236. } else {
  237. parent::sendOutput($result->getData(), $result->getErrorCode());
  238. }
  239. }
  240. /**
  241. * 测试出库
  242. */
  243. public function addDocument(){
  244. $params = $this->request->getRawJson();
  245. $objMDocument = new MDocument($this->onlineEnterpriseId);
  246. $result = $objMDocument->addDocument($params);
  247. if ($result->isSuccess()) {
  248. parent::sendOutput($result->getData());
  249. } else {
  250. parent::sendOutput($result->getData(), $result->getErrorCode());
  251. }
  252. }
  253. }