WarehousingDetail.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Session;
  5. use think\Db;
  6. use think\Where;
  7. /**
  8. * 油墨库存管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class WarehousingDetail extends Backend
  13. {
  14. /**
  15. * Warehousing模型对象
  16. * @var \app\admin\model\Warehousing
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\WarehousingDetail();
  23. $this->view->assign("isScrapList", $this->model->getIsScrapList());
  24. $this->view->assign("statusList", $this->model->getStatusList());
  25. }
  26. /**
  27. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  28. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  29. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  30. */
  31. public function index()
  32. {
  33. //设置过滤方法
  34. $this->request->filter(['strip_tags']);
  35. if ($this->request->isAjax()) {
  36. //如果发送的来源是Selectpage,则转发到Selectpage
  37. if ($this->request->request('keyField')) {
  38. return $this->selectpage();
  39. }
  40. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  41. $search = input('search');
  42. $map=array();
  43. if (!empty($search)){
  44. $map['formula'] = array('like',"%$search%");
  45. }
  46. $total = Db::name('warehousing')
  47. ->order('update desc')
  48. ->where($map)
  49. ->count();
  50. $list = Db::name('warehousing')
  51. ->order('update desc')
  52. ->where($map)
  53. ->limit($offset, $limit)
  54. ->select();
  55. $list = collection($list)->toArray();
  56. $result = array("total" => $total, "rows" => $list);
  57. return json($result);
  58. }
  59. return $this->view->fetch();
  60. }
  61. //增加库存
  62. public function add()
  63. {
  64. if ($this->request->isPost()) {
  65. $params = $this->request->post("row/a");
  66. //过滤前台传的字段
  67. $params = $this->preExcludeFields($params);
  68. // print_r($params);die;
  69. if (empty($params['cid'])){
  70. return array('status'=>0,'msg'=>'请请选择颜色');
  71. }
  72. //专色墨批次 由产品编码+时间+色号+人员编号+'-'+当日本产品第几次调墨
  73. //产品编码
  74. $product_number = $params['product_number'];
  75. //时间取6位
  76. $time = date('Ymd');
  77. $time = substr($time,-6);
  78. $user = Session::get('admin');
  79. $name = $user['nickname'];
  80. //人员编号,根据缓存的nickname确认人员编号
  81. $people_number = Db::name('people')->where('name',$name)->value('number');
  82. //色号,根据产品编码和颜色 确定它的色号
  83. $color_number = Db::name('formula')->where('id',$params['cid'])->value('color_number');
  84. $params['color'] = Db::name('formula')->where('id',$params['cid'])->value('color');
  85. //查这个色号当日第几次调配
  86. $num = Db::name('warehousing_detail')->where('product_number',$product_number)->where('cid',$params['cid'])->whereTime('create','today')->count();
  87. if (empty($num)){
  88. $color = 1;
  89. }else{
  90. $color = $num + 1;
  91. }
  92. //专色墨批次号
  93. $params['bach_number'] = $product_number.$time.$color_number.$people_number.'-'.$color;
  94. $params['weight'] = $params['weight'] * 1000;
  95. $params['create'] = date('Y-m-d H:i:s');
  96. Db::startTrans();
  97. try{
  98. $id = Db::name('warehousing_detail')->insertGetId($params);
  99. if (empty($id)){
  100. throw new Exception('插入数据失败,请联系开发人员');
  101. }
  102. $totalWeight = Db::name('warehousing')->where('product_name',$params['product_name'])->where('cid',$params['cid'])->find();
  103. if (!empty($totalWeight)){
  104. $totalWeight['weight'] = $totalWeight['weight'] + $params['weight'];
  105. Db::name('warehousing')->where('product_name',$params['product_name'])->where('cid',$params['cid'])->setField('weight',$totalWeight['weight']);
  106. Db::name('warehousing')->where('product_name',$params['product_name'])->where('cid',$params['cid'])->setField('update',date('Y-m-d H:i:s'));
  107. }else{
  108. $data = array();
  109. $data['weight'] = $params['weight'];
  110. $data['product_name'] = $params['product_name'];
  111. $data['product_number'] = $params['product_number'];
  112. $data['formula'] = $params['formula'];
  113. $data['cid'] = $params['cid'];
  114. $data['color'] = $params['color'];
  115. $data['update'] = date('Y-m-d H:i:s');
  116. Db::name('warehousing')->insert($data);
  117. }
  118. Db::commit();
  119. $this->success();
  120. }catch (\think\Exception\DbException $exception){
  121. Db::rollback();
  122. $this->error(__('No rows were inserted'));
  123. }
  124. }
  125. //检索数据
  126. $data = Db::connect('db2')->query("select 产品名称 from 产品_基本资料 where 状态 = '' ");
  127. $backData = array();
  128. foreach ($data as $key=>$value){
  129. $backData[$key] = trim($value['产品名称']);
  130. }
  131. return $this->view->fetch('',compact('backData'));
  132. }
  133. //查看油墨详情
  134. public function read(){
  135. $params = input('');
  136. $warehousing = Db::name('warehousing')->where('id', $params['ids'])->find();
  137. $result = Db::name('warehousing_detail')->where('cid', $warehousing['cid'])->where('status',0)->order('id desc')->select();
  138. return $this->view->fetch('',compact('result'));
  139. }
  140. //获取某个产品色号
  141. public function getColor(){
  142. $params = input('data');
  143. if (is_numeric($params)){//传递来的是产品编号
  144. $product_number = trim($params);
  145. $where[] = ['exp',Db::raw("FIND_IN_SET($product_number,product_number)")];
  146. $result = Db::name('formula')
  147. ->where($where)
  148. ->select();
  149. }else{//传递来的是产品名称
  150. $product = Db::connect('db2')->query("select * from 工单_基本资料 where 成品名称 = '{$params}' limit 1");
  151. if (empty($product)){
  152. return array('status'=>0,'msg'=>'MES库不存在,请重新选择产品名称');
  153. }
  154. $product_number = rtrim($product[0]['Gd_cpdh']);
  155. $where[] = ['exp',Db::raw("FIND_IN_SET($product_number,product_number)")];
  156. $result = Db::name('formula')
  157. ->where($where)
  158. ->select();
  159. }
  160. $fomulaData = array();
  161. foreach ($result as $key=>$value){
  162. $result[$key]['product_number'] = $product_number;
  163. $fomulaData[$key] = $value['product_name'];
  164. if ($key > 0){
  165. if ($value['product_name'] != $result[$key-1]['product_name']){
  166. $fomulaData[$key] = $value['product_name'];
  167. }else{
  168. unset($fomulaData[$key]);
  169. }
  170. }
  171. }
  172. if (!empty($result)){
  173. return array('status'=>1,'msg'=>'请求成功','data'=>$result,'formula'=>$fomulaData);
  174. }else{
  175. return array('status'=>0,'msg'=>'未查询到数据');
  176. }
  177. }
  178. }