Goods.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. namespace app\admin\controller\company;
  3. use app\admin\controller\AuthController;
  4. use app\models\system\SystemStore;
  5. use app\models\system\SystemStoreStock;
  6. use app\models\system\SystemStoreStockBill;
  7. use app\admin\model\store\{
  8. StoreCategory as CategoryModel,
  9. StoreProduct as ProductModel
  10. };
  11. use crmeb\services\{JsonService, JsonService as Json, UtilService as Util, FormBuilder as Form};
  12. use crmeb\traits\CurdControllerTrait;
  13. use think\facade\Route as Url;
  14. /**
  15. * 产品管理
  16. * Class StoreProduct
  17. * @package app\admin\controller\store
  18. */
  19. class Goods extends AuthController
  20. {
  21. use CurdControllerTrait;
  22. protected $bindModel = ProductModel::class;
  23. /**
  24. * 显示资源列表
  25. *
  26. * @return \think\Response
  27. */
  28. public function index()
  29. {
  30. $type = $this->request->param('type', 1);
  31. //获取分类
  32. $this->assign('cate', CategoryModel::getTierList(null, 1));
  33. //出售中产品
  34. $onsale = ProductModel::where('is_del', 0)->where('is_consumer',0)->where('is_show', 1)->count();
  35. //待上架产品
  36. $forsale = ProductModel::where('is_del', 0)->where('is_consumer',0)->where('is_show', 0)->count();
  37. //仓库中产品
  38. $warehouse = ProductModel::where('is_del', 0)->where('is_consumer',0)->count();
  39. //已经售馨产品
  40. $outofstock = ProductModel::getModelObject(['type' => 4])->where('is_consumer',0)->count();
  41. //警戒库存
  42. $policeforce = ProductModel::getModelObject(['type' => 5])->where('is_consumer',0)->count();
  43. //回收站
  44. $recycle = ProductModel::where('is_del', 1)->where('is_consumer',0)->count();
  45. $this->assign(compact('type', 'onsale', 'forsale', 'warehouse', 'outofstock', 'policeforce', 'recycle'));
  46. $this->assign('type',$this->adminInfo['type']);
  47. if($this->adminInfo['type']==0)
  48. {
  49. $this->assign('store',SystemStore::where('is_show',1)->where('is_del',0)->field('id,name')->select());
  50. }
  51. return $this->fetch();
  52. }
  53. public function consumer()
  54. {
  55. $type = $this->request->param('type', 1);
  56. //获取分类
  57. $this->assign('cate', CategoryModel::getTierList(null, 1,1));
  58. //出售中产品
  59. $onsale = ProductModel::where('is_del', 0)->where('is_show', 1)->where('is_consumer',1)->count();
  60. //待上架产品
  61. $forsale = ProductModel::where('is_del', 0)->where('is_show', 0)->where('is_consumer',1)->count();
  62. //仓库中产品
  63. $warehouse = ProductModel::where('is_del', 0)->where('is_consumer',1)->count();
  64. //已经售馨产品
  65. $outofstock = ProductModel::getModelObject(['type' => 4])->where('is_consumer',1)->count();
  66. //警戒库存
  67. $policeforce = ProductModel::getModelObject(['type' => 5])->where('is_consumer',1)->count();
  68. //回收站
  69. $recycle = ProductModel::where('is_del', 1)->where('is_consumer',1)->count();
  70. $this->assign(compact('type', 'onsale', 'forsale', 'warehouse', 'outofstock', 'policeforce', 'recycle'));
  71. return $this->fetch();
  72. }
  73. /**
  74. * 异步查找产品
  75. *
  76. * @return json
  77. */
  78. public function product_ist()
  79. {
  80. $where = Util::getMore([
  81. ['page', 1],
  82. ['limit', 20],
  83. ['key',''],
  84. ['excel', 0],
  85. ['store_id',$this->adminInfo['store_id']],
  86. ['is_warn',0],
  87. ]);
  88. return Json::successlayui(SystemStoreStock::lst($where));
  89. }
  90. /**
  91. * 显示创建资源表单页.
  92. *
  93. * @return \think\Response
  94. */
  95. public function create($id = 0,$consumer=0)
  96. {
  97. $this->assign('id', (int)$id);
  98. $this->assign('consumer', (int)$consumer);
  99. return $this->fetch();
  100. }
  101. public function save()
  102. {
  103. $where = Util::getMore([
  104. ['bar_code', 20],
  105. ['in_stock',0],
  106. ]);
  107. if($where['in_stock']<1) return app('json')->fail('补货数量不能少于1');
  108. $info = SystemStoreStock::alias('a')->join("StoreProduct b","a.product_id=b.id","left")->where('a.bar_code',$where['bar_code'])->field('a.price,a.unique,a.in_stock,a.is_consumer,a.product_id,b.store_name,b.image,a.bar_code')->find();
  109. if(!$info) return app('json')->fail('商品条形码不存在');
  110. $info = $info->toarray();
  111. $info['in_stock'] = $where['in_stock'];
  112. $info['admin_id'] = $this->adminId;
  113. if(SystemStoreStockBill::order_create($this->adminInfo['store_id'],$info))
  114. {
  115. return Json::successful('入库成功');
  116. }
  117. else
  118. {
  119. return Json::fail('入库失败');
  120. }
  121. }
  122. /**
  123. * 门店库存始初化
  124. * @param int $store_id
  125. * @param int $num
  126. */
  127. public function init($store_id=0,$num=10)
  128. {
  129. if ($store_id<1) return app('json')->fail('参数错误!');
  130. if($this->adminInfo['type']==1) return app('json')->fail('无权限!');
  131. SystemStoreStock::store_init($store_id,$num);
  132. }
  133. public function bill()
  134. {
  135. if($this->adminInfo['type']==0)
  136. {
  137. $this->assign('store',SystemStore::where('is_show',1)->where('is_del',0)->field('id,name')->select());
  138. }
  139. $this->assign('type',$this->adminInfo['type']);
  140. return $this->fetch();
  141. }
  142. public function bill_lst()
  143. {
  144. $where = Util::getMore([
  145. ['store_id', $this->adminInfo['store_id']],
  146. ['key',''],
  147. ['page',0],
  148. ['limit',0],
  149. ['status',-2],
  150. ]);
  151. return Json::successlayui(SystemStoreStockBill::lst($where));
  152. }
  153. public function bill_view($product_id,$store_id)
  154. {
  155. $this->assign('product_id',$product_id);
  156. $this->assign('store_id',$store_id);
  157. $this->assign('count',SystemStoreStockBill::where(compact('product_id','store_id'))->value('count(id)')?:0);
  158. return $this->fetch();
  159. }
  160. public function bill_view_lst()
  161. {
  162. $where = Util::getMore([
  163. ['store_id',0],
  164. ['product_id',0],
  165. ['key',''],
  166. ['page',0],
  167. ['limit',0],
  168. ['status',-2],
  169. ]);
  170. return app('json')->successful(SystemStoreStockBill::lst($where));
  171. }
  172. public function audit($id)
  173. {
  174. if (!$id) return $this->failed('数据不存在');
  175. $Bill = SystemStoreStockBill::where('id',$id)->find();
  176. if (!$Bill) return Json::fail('数据不存在!');
  177. $f = array();
  178. $f[] = Form::radio('status', '状态', $Bill->getData('status'))->options([['value' => 1, 'label' => '通过'], ['value' => -1, 'label' => '拒绝']]);
  179. $f[] = Form::textarea('refuse_msg','备注');
  180. $form = Form::make_post_form('入库审核', $f, Url::buildUrl('audit_save', array('id' => $id)), 2);
  181. $this->assign(compact('form'));
  182. return $this->fetch('public/form-builder');
  183. }
  184. public function batch_audit($id)
  185. {
  186. if (!$id) return $this->failed('数据不存在');
  187. $f = array();
  188. $f[] = Form::radio('status', '状态')->options([['value' => 1, 'label' => '通过'], ['value' => -1, 'label' => '拒绝']]);
  189. $f[] = Form::textarea('refuse_msg','备注');
  190. $form = Form::make_post_form('入库审核', $f, Url::buildUrl('batch_audit_save', array('id' => $id)), 2);
  191. $this->assign(compact('form'));
  192. return $this->fetch('public/form-builder');
  193. }
  194. public function audit_save($id)
  195. {
  196. $where = Util::postMore([
  197. ['refuse_msg',''],
  198. ['status',1],
  199. ]);
  200. if(!SystemStoreStockBill::be(['id'=>$id,'status'=>0])) return $this->failed('数据不存在或已经审核');
  201. $where['audit_time'] = time();
  202. $where['audit_admin'] = $this->adminId;
  203. SystemStoreStockBill::edit($where,$id);
  204. if($where['status']==1) {
  205. $info = SystemStoreStockBill::find($id)->toArray();
  206. $rs = SystemStoreStock::replenish($info['store_id'], $info);
  207. }
  208. return Json::successful('审核成功');
  209. }
  210. /**
  211. * 批量审核
  212. */
  213. public function batch_audit_save()
  214. {
  215. $where = Util::postMore([
  216. ['refuse_msg',''],
  217. ['status',1],
  218. ]);
  219. $ids = explode(',',input('id'));
  220. if($where['status']==1)
  221. {
  222. foreach ($ids as $v)
  223. {
  224. $info = SystemStoreStockBill::where('id',$v)->where('status',0)->find();
  225. if($info)
  226. {
  227. $rs = SystemStoreStock::replenish($info['store_id'], $info);
  228. }
  229. }
  230. }
  231. $where['audit_time'] = time();
  232. $where['audit_admin'] = $this->adminId;
  233. SystemStoreStockBill::where('id','in',join(",",$ids))->update($where);
  234. return Json::successful('批量审核成功');
  235. }
  236. }