Consume.Class.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. /**
  3. * 商铺管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Controller\Stock;
  10. use JinDouYun\Dao\Stock\DInventoryIn;
  11. use JinDouYun\Dao\Stock\DInventoryInDetails;
  12. use JinDouYun\Dao\Stock\DInventoryOutDetails;
  13. use JinDouYun\Dao\Stock\DInventoryWarehouse;
  14. use JinDouYun\Dao\Stock\DInventory;
  15. use JinDouYun\Dao\GoodsManage\DGoodsBasic;
  16. use JinDouYun\Dao\UserCenter\DUserCenter;
  17. use JinDouYun\Model\Shop\MShop;
  18. use JinDouYun\Model\Stock\MConsume;
  19. use JinDouYun\Model\Stock\MInventory;
  20. use Mall\Framework\Core\ErrorCode;
  21. use Mall\Framework\Core\ResultWrapper;
  22. use Mall\Framework\Core\StatusCode;
  23. use JinDouYun\Dao\Stock\DInventoryOut;
  24. use JinDouYun\Cache\ShopCache;
  25. use JinDouYun\Controller\BaseController;
  26. use JinDouYun\Cache\TempSaveCache;
  27. class Consume extends BaseController
  28. {
  29. private $obj;
  30. private $objShopCache;
  31. private $objTempSaveCache;
  32. private $objin;
  33. private $objshop;
  34. private $objinvin;
  35. public function __construct($isCheckAcl = true, $isMustLogin = true)
  36. {
  37. parent::__construct($isCheckAcl, $isMustLogin);
  38. $this->obj = new MConsume($this->onlineEnterpriseId, $this->onlineUserId);
  39. $this->objin = new DInventoryWarehouse('stock');
  40. $this->objinv = new DInventory('stock');
  41. $this->objinvin = new DInventoryInDetails('stock');
  42. $this->objGoog = new DGoodsBasic('default');
  43. $this->objin->setTable('qianniao_inventory_warehouse_'.$this->onlineEnterpriseId);
  44. $this->objGoog->setTable('qianniao_goods_basic_'.$this->onlineEnterpriseId);
  45. $this->objinv->setTable('qianniao_inventory_'.$this->onlineEnterpriseId);
  46. $this->objinvin->setTable('qianniao_inventory_in_details_'.$this->onlineEnterpriseId);
  47. $this->user = new DUserCenter('default');
  48. $this->objshop = new MShop($this->onlineEnterpriseId);
  49. }
  50. /**
  51. * 添加和编辑商铺管理公共字段处理方法
  52. *
  53. * @return array
  54. */
  55. public function commonFieldFilter(){
  56. $params = $this->request->getRawJson();
  57. if( empty($params) ){
  58. $this->sendOutput('参数为空', ErrorCode::$paramError );
  59. }
  60. $shopData = [
  61. // 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  62. 'id' => isset($params['id']) ? $params['id'] : '',
  63. 'number' => isset($params['number']) ? $params['number'] : '',
  64. ];
  65. //非暂存则验空
  66. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  67. foreach($shopData as $key => $value){
  68. if(empty($value) && $value !== 0){
  69. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  70. }
  71. }
  72. }
  73. return $shopData;
  74. }
  75. /**
  76. * 列表
  77. */
  78. public function list()
  79. {
  80. $params = $this->request->getRawJson();
  81. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  82. $selectParams['limit'] = $pageParams['limit'];
  83. $selectParams['offset'] = $pageParams['offset'];
  84. //uid
  85. if(isset($params['status']) && !empty($params['status'])){
  86. if ($params['status'] == 1){
  87. $selectParams['status'] = 1;
  88. }
  89. if ($params['status'] == 2){
  90. $selectParams['status'] = 2;
  91. }
  92. }
  93. if ($this->shopId){
  94. $selectParams['shopId'] = $this->shopId;
  95. }
  96. if (isset($params['shopId']) and !empty($params['shopId'])){
  97. $selectParams['shopId'] = $params['shopId'];
  98. }
  99. if ($params['name']){
  100. $selectParams['name'] = $params['name'];
  101. }
  102. if ($params['mobile']){
  103. $selectParams['mobile'] = $params['mobile'];
  104. }
  105. if ($params['write_mobile']){
  106. $selectParams['write_mobile'] = $params['write_mobile'];
  107. }
  108. if(isset($params['start_time']) && !empty($params['start_time'])){
  109. $selectParams['start_time'] = $params['start_time'];
  110. }
  111. if(isset($params['end_time']) && !empty($params['end_time'])){
  112. $selectParams['end_time'] = $params['end_time'];
  113. }
  114. $result = $this->obj->list($selectParams);
  115. if ($result->isSuccess()) {
  116. $returnData = $result->getData();
  117. $pageData = [
  118. 'pageIndex' => $params['page'],
  119. 'pageSize' => $params['pageSize'],
  120. 'pageTotal' => $returnData['total'],
  121. ];
  122. parent::sendOutput($returnData['data'], 0, $pageData);
  123. } else {
  124. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  125. }
  126. }
  127. /**
  128. * 添加
  129. * @throws \Exception
  130. */
  131. public function allocation()
  132. {
  133. $addStaffData = $this->commonFieldFilter();
  134. $this->objin->beginTransaction();
  135. $in = $this->objin->get(['id' => $addStaffData['id']]);
  136. $good = $this->objinvin->get(['linkId' => $in['materielId']]);
  137. if ($in['inventoryNum'] < $addStaffData['number']) parent::sendOutput('库存不足', ErrorCode::$dberror);
  138. $goods = $this->objGoog->get(['id' => $in['materielId']]);
  139. $id = $addStaffData['id'];
  140. $addStaffData['name'] = $goods['title'];
  141. $addStaffData['image'] = json_decode($goods['images'])[0];
  142. $addStaffData['shopId'] = $this->shopId;
  143. $addStaffData['enterpriseId'] = $this->onlineEnterpriseId;
  144. $addStaffData['userCenterId'] = $this->onlineUserId;
  145. $addStaffData['warehouseId'] = $in['warehouseId'];
  146. unset($addStaffData['id']);
  147. $result = $this->obj->insert($addStaffData);
  148. if ($result->isSuccess()) {
  149. $number = $in['inventoryNum'] - $addStaffData['number'];
  150. $this->objin->update(['inventoryNum' => $number], $in['id']);
  151. $this->objinv->update(['inventoryNum' => $number], $in['id']);
  152. $orderId = date('Ymd-'.rand(1000, 9999));
  153. $shop = $this->objshop->getShopData(['id' => $this->shopId])->getData()[0];
  154. $data = [
  155. 'no' => $orderId,
  156. 'sourceId' => $this->shopId,
  157. 'sourceNo' => $orderId,
  158. 'originNo' => $orderId,
  159. 'originId' => $id,
  160. 'materielNum' => $addStaffData['number'],
  161. 'shopId' => $this->shopId,
  162. 'shopName' => $shop['name'],
  163. 'operatorId' => $this->onlineUserId,
  164. 'operatorName' => '员工',
  165. 'remark' => '消耗品调拨',
  166. 'source' => 1,
  167. 'deliveryType' => 2,
  168. 'type' => 16,
  169. 'deleteStatus' => 5,
  170. 'outStatus' => 2,
  171. 'auditStatus' => 2,
  172. 'createTime' => time(),
  173. 'auditTime' => time(),
  174. 'updateTime' => time(),
  175. 'serialNum' => $orderId
  176. ];
  177. $db = new DInventoryOut('stock');
  178. $db->setTable($db->get_Table() . '_' . $this->onlineEnterpriseId);
  179. $res = $db->insert($data);
  180. $ins = [
  181. 'linkId' => $res,
  182. 'linkNo' => $orderId,
  183. 'outWarehouse' => json_encode([[
  184. 'num' => $addStaffData['number'],
  185. 'otherNum' => '0.00000000',
  186. 'warehouseId' => $in['warehouseId']
  187. ]]),
  188. 'materielId' => $good['materielId'],
  189. 'materielName' => $good['materielName'],
  190. 'materielCode' => $good['materielCode'],
  191. 'unitName' => $good['unitName'],
  192. 'skuId' => $good['skuId'],
  193. 'skuName' => $good['skuName'],
  194. 'num' => 0,
  195. 'outNum' => $addStaffData['number'],
  196. 'otherNum' => 0,
  197. 'total' => $addStaffData['number'],
  198. 'unitPrice' => 0,
  199. 'totalPrice' => 0,
  200. 'createTime' => time(),
  201. 'updateTime' => time(),
  202. 'isEq' => 4,
  203. 'extend' => 'null',
  204. ];
  205. $dbs = new DInventoryOutDetails('stock');
  206. $dbs->setTable($dbs->get_Table() . '_' . $this->onlineEnterpriseId);
  207. $dbs->insert($ins);
  208. $this->objin->commit();
  209. parent::sendOutput('成功');
  210. } else {
  211. $this->objin->rollBack();
  212. parent::sendOutput($result->getData(), $result->getErrorCode());
  213. }
  214. }
  215. /**
  216. * 详情
  217. * @return void
  218. */
  219. public function details()
  220. {
  221. $where = [];
  222. $id = $this->request->param('id');
  223. if(!empty($id)){
  224. $where['id'] = $id;
  225. }
  226. $result = $this->obj->details($where);
  227. if ($result->isSuccess()) {
  228. parent::sendOutput($result->getData());
  229. } else {
  230. parent::sendOutput($result->getData(), $result->getErrorCode());
  231. }
  232. }
  233. /**
  234. * 修改
  235. * @return void
  236. */
  237. public function write_off()
  238. {
  239. $id['id'] = $this->request->param('id');
  240. if (empty($id['id'])) {
  241. $this->sendOutput('参数为空', ErrorCode::$paramError);
  242. }
  243. $params['status'] = 2;
  244. $params['write'] = $this->onlineUserId;
  245. $params['writeTime'] = time();
  246. $result = $this->obj->update($params, $id);
  247. if ($result->isSuccess()) {
  248. parent::sendOutput($result->getData());
  249. } else {
  250. parent::sendOutput($result->getData(), $result->getErrorCode());
  251. }
  252. }
  253. public function delete()
  254. {
  255. $id['id'] = $this->request->param('id');
  256. if (empty($id['id'])) {
  257. $this->sendOutput('参数为空', ErrorCode::$paramError);
  258. }
  259. $result = $this->obj->delete($id);
  260. if ($result->isSuccess()) {
  261. parent::sendOutput($result->getData());
  262. } else {
  263. parent::sendOutput($result->getData(), $result->getErrorCode());
  264. }
  265. }
  266. }