Formula.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Session;
  5. use think\Db;
  6. /**
  7. * 配方管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Formula extends Backend
  12. {
  13. /**
  14. * Formula模型对象
  15. * @var \app\admin\model\Formula
  16. */
  17. protected $model = null;
  18. protected $searchFields = "name";
  19. protected $noNeedLogin = ['gyName'];
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\Formula;
  24. $this->view->assign("examineStatusList", $this->model->getExamineStatusList());
  25. $this->view->assign("statusList", $this->model->getStatusList());
  26. // $this->view->assign("gyNameList", \app\admin\model\GyName::select());
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. /**
  34. * 查看
  35. *
  36. * @return string|Json
  37. * @throws \think\Exception
  38. * @throws DbException
  39. */
  40. public function index()
  41. {
  42. //设置过滤方法
  43. $this->request->filter(['strip_tags', 'trim']);
  44. if (false === $this->request->isAjax()) {
  45. return $this->view->fetch();
  46. }
  47. // 获取搜索框的值
  48. $map = [];
  49. $filter=input('filter');
  50. if($filter){
  51. $filter=urldecode($filter);
  52. $filter=json_decode($filter,TRUE);
  53. foreach($filter as $k=>$v){
  54. $map[$k]=['like',"%{$v}%"];
  55. }
  56. }
  57. //如果发送的来源是 Selectpage,则转发到 Selectpage
  58. if ($this->request->request('keyField')) {
  59. return $this->selectpage();
  60. }
  61. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  62. $user_info = Session::get('admin');
  63. if ($user_info['id'] !== 1){//管理员
  64. $map['company_id'] = $user_info['company_id'];
  65. $map['examine_status'] = 2;
  66. }
  67. if(!empty($map['name'])||!empty($map['material'])){
  68. $sort = 'f.id';
  69. $list = DB::name('formula')
  70. ->where($where)
  71. ->where($map)
  72. ->alias('f')
  73. ->group('f.id')
  74. ->field('f.id,f.name,f.version,f.examine_status,f.create')
  75. ->join('formula_detail fd','fd.pid=f.id','left')
  76. ->order($sort, $order)
  77. ->paginate($limit);
  78. }else{
  79. $list = $this->model
  80. ->where($where)
  81. ->where($map)
  82. ->order($sort, $order)
  83. ->paginate($limit);
  84. }
  85. $result = ['total' => $list->total(), 'rows' => $list->items()];
  86. return json($result);
  87. }
  88. /**
  89. * 添加
  90. *
  91. * @return string
  92. * @throws \think\Exception
  93. */
  94. public function add()
  95. {
  96. if (false === $this->request->isPost()) {
  97. //技术部=>担当人
  98. $jsdd = Db::name('personnel')->where('bid',"=",2)->where('position','=',"jsdd")->order('name desc')->select();
  99. //技术部=>审核人
  100. $jssh = Db::name('personnel')->where('bid',"=",2)->where('position','=',"jssh")->order('name desc')->select();
  101. $this->assign('jsdd',$jsdd);
  102. $this->assign('jssh',$jssh);
  103. return $this->view->fetch();
  104. }
  105. $base = $this->request->post('baseData/a');
  106. $formula = $this->request->post('formulaData/a');
  107. if (empty($base) || empty($formula)){
  108. $this->error('数据不能为空');
  109. }
  110. $params = [];
  111. $params['name'] = $base[0];
  112. $params['no'] = $base[1];
  113. $params['charge_name'] = $base[2];
  114. $params['examine_name'] = $base[3];
  115. $params['remark'] = $base[4];
  116. $params['version'] = $base[5];
  117. $params['date'] = $base[6];
  118. $params['model'] = $base[8];
  119. if ($base[7] !== 99){
  120. $customer= explode(',',$base[7]);
  121. // print_r($base[7]);die;
  122. $customer_id = Db::name('customer')->where('customer_name','in',$customer)->column('id');
  123. $usability = implode(',',$customer_id);
  124. }
  125. $params['usability'] = $usability;
  126. $params['create'] = date('Y-m-d H:i:s');
  127. $user_info = Session::get('admin');
  128. $params['user_id'] = $user_info['id'];
  129. $params['company_id'] = $user_info['company_id'];
  130. $result = false;
  131. Db::startTrans();
  132. try {
  133. $pid = Db::name('formula')->insertGetId($params);
  134. if (!$pid){
  135. Db::rollback();
  136. $this->error('数据未插入,请重新操作');
  137. }
  138. $data = [];
  139. $is_replace = 0;
  140. // $gy_num = 1;
  141. foreach($formula as $key=>$value){
  142. if (strpos($value[0],'/') === false){
  143. $data[$key]['is_replace'] = 0;
  144. }else{
  145. $data[$key]['is_replace'] = 1;
  146. $is_replace = 1;
  147. }
  148. $data[$key]['material'] = $value[0];
  149. $data[$key]['percentage'] = encrypt($value[1]);
  150. $data[$key]['gy_name'] = $value[2];
  151. // $data[$key]['gy_num'] = $gy_num;
  152. $data[$key]['gy_num'] = $value[3];
  153. $data[$key]['pid'] = $pid;
  154. $data[$key]['version'] = $params['version'];
  155. $data[$key]['create'] = $params['create'];
  156. // if(!$value[0]&&!$value[1]&&$value[2]){
  157. // $gy_num++;
  158. // }
  159. }
  160. $result = Db::name('formula_detail')->insertAll($data);
  161. //有替代料的话 查出所有替代料 然后分解 插入到数据库 2022年9月19日14:20:37 替代料功能改变
  162. // if ($is_replace == 1){
  163. // $replace = Db::name('formula_detail')->where('pid',$pid)->where('is_replace',1)->field('id,material')->select();
  164. // $replaceData = [];
  165. // $j = 0;
  166. // foreach ($replace as $k=>$v){
  167. // $material = explode('/',$v['material']);
  168. // for ($i=0;$i<count($material);$i++){
  169. // $replaceData[$j]['fid'] = $v['id'];
  170. // $replaceData[$j]['material'] = $material[$i];
  171. // $replaceData[$j]['create'] = date('Y-m-d H:i:s');
  172. // $j++;
  173. // }
  174. // }
  175. // $result = Db::name('formula_replace')->insertAll($replaceData);
  176. // }
  177. Db::commit();
  178. } catch (Exception $e) {
  179. Db::rollback();
  180. $this->error($e->getMessage());
  181. }
  182. if ($result === false) {
  183. $this->error(__('No rows were inserted'));
  184. }
  185. $this->success();
  186. }
  187. /**
  188. * 编辑
  189. *
  190. * @param $ids
  191. * @return string
  192. * @throws DbException
  193. * @throws \think\Exception
  194. */
  195. public function edit($ids = null)
  196. {
  197. if (!$ids) {
  198. $this->error(__('No Results were found'));
  199. }
  200. if (false === $this->request->isPost()) {
  201. $ids = input('ids');
  202. $order = Db::name('order')->field('user_name,examine,customer')->where('id',"=",$ids)->find();
  203. //查询公司
  204. $customer_name = Db::name('customer')->field('id,customer_name')->where('customer_name','=',$order['customer'])->find();
  205. $this->assign('customer_name',$customer_name);
  206. $customer = Db::name('customer')->field('customer_name')->select();
  207. $this->assign('customer',$customer);
  208. //查询 经办 审核
  209. $jsdd = Db::name('personnel')->where('bid',"=",2)->where('position','=',"jsdd")->order('name desc')->select();
  210. $jssh = Db::name('personnel')->where('bid',"=",2)->where('position','=',"jssh")->order('name desc')->select();
  211. $personnel_jsdd = Db::name('personnel')->where('name','=',$order['user_name'])->find();
  212. $personnel_jssh = Db::name('personnel')->where('name','=',$order['examine'])->find();
  213. $this->assign('jsdd',$jsdd);
  214. $this->assign('jssh',$jssh);
  215. $this->assign('personnel_jsdd',$personnel_jsdd);
  216. $this->assign('personnel_jssh',$personnel_jssh);
  217. $list = Db::name('formula')->where('id',$ids)->find();
  218. //可用性,对应客户名称
  219. if ($list['usability'] != 99){
  220. $customer = explode(',',$list['usability']);
  221. $name = Db::name('customer')->where('id','in',$customer)->column('customer_name');
  222. }
  223. $list['gyinfo'] = Db::name('formula_detail')->where('pid',$ids)->where('version',$list['version'])->field('material,percentage,gy_name,gy_num')->select();
  224. foreach ($list['gyinfo'] as $key=>$value){
  225. $list['gyinfo'][$key]['percentage'] = decode($value['percentage']);
  226. }
  227. // dump($list);die;
  228. $this->view->assign('ids',$ids);
  229. $this->view->assign('name',$name);
  230. $this->view->assign('row', $list);
  231. return $this->view->fetch();
  232. }
  233. /**
  234. * 厂家变更?
  235. * 原材料变更?
  236. * 百分比变更? ->工艺信息变更生成新配方
  237. * 工艺变更?
  238. * $change 0:未更改工艺信息 1:原材料更改 2:百分比更改 3:操作工艺更改 4:增加或减少工艺信息
  239. */
  240. $base = $this->request->post('baseData/a');
  241. $formula = $this->request->post('formulaData/a');
  242. if (empty($base) || empty($formula)){
  243. $this->error('数据不能为空');
  244. }
  245. $version = Db::name('formula')->where('name',$base[0])->order('id desc')->value('version');
  246. $version = substr($version,1);//获取当前最新版本号,后续看工艺情况是否更改
  247. //基础数据
  248. $params = [];
  249. $params['name'] = $base[0];
  250. $params['no'] = $base[1];
  251. $params['charge_name'] = $base[2];
  252. $params['examine_name'] = $base[3];
  253. $params['remark'] = $base[4];
  254. $params['date'] = $base[6];
  255. $params['model'] = $base[8];
  256. //配方对应客户id(可用性)
  257. if ($base[7] !== 99){
  258. $customer= explode(',',$base[7]);
  259. $customer_id = Db::name('customer')->where('customer_name','in',$customer)->column('id');
  260. $usability = implode(',',$customer_id);
  261. }
  262. $params['usability'] = $usability;
  263. $params['create'] = date('Y-m-d H:i:s');
  264. $user_info = Session::get('admin');
  265. $params['user_id'] = $user_info['id'];
  266. $params['company_id'] = $user_info['company_id'];
  267. $params['update'] = date('Y-m-d H:i:s');
  268. //数据库的工艺数据
  269. $gy_data = Db::name('formula_detail')->where('pid',$ids)->field('id,material,percentage,gy_name')->order('id asc')->select();
  270. //提交的工艺数据
  271. $data = [];
  272. $change = 0;
  273. $materialChange = 0; //原材料变更
  274. $percentageChange = 0; //百分比变更
  275. $gy_nameChange = 0; //工艺信息变更
  276. //总工艺已更改,版本号X位直接增加1
  277. if (count($gy_data) != count($formula)){
  278. $change = 1;
  279. }
  280. foreach($formula as $key=>$value){
  281. foreach ($gy_data as $k=>$v){
  282. //比对同一行原材料 百分比 工艺信息
  283. if ($key == $k){
  284. if ($value[0] != $gy_data[$k]['material']){
  285. $materialChange = 1;
  286. }
  287. if ($value[1] != $gy_data[$k]['percentage']){
  288. $percentageChange = 1;
  289. }
  290. if($value[2] != $gy_data[$k]['gy_name']){
  291. $gy_nameChange = 1;
  292. }
  293. }
  294. }
  295. }
  296. //更改版本号
  297. if ($change === 1){
  298. $version = intval($version) + 1;
  299. }else{
  300. if ($materialChange === 1){
  301. $version = intval($version) + 1;
  302. }else{
  303. if ($percentageChange === 1 || $gy_nameChange === 1){
  304. $version = $version + 0.1;
  305. }
  306. }
  307. }
  308. if (is_int($version)){
  309. $version = $version.'.0';
  310. }
  311. //根据版本号的变化来判断工艺有没有变化
  312. if ($version == substr($base[5],1)){
  313. $isChange = false;
  314. }else{
  315. $isChange = true;
  316. }
  317. $params['version'] = 'v'.$version;
  318. $result = true;
  319. Db::startTrans();
  320. try {
  321. if ($isChange === true){
  322. $ids = Db::name('formula')->insertGetId($params);
  323. }else{
  324. Db::name('formula')->where('id',$ids)->update($params);
  325. }
  326. //新工艺信息
  327. $is_replace = 0;
  328. for($i=0;$i<count($formula);$i++){
  329. if (strpos($formula[$i][0],'/') === false){
  330. $data[$i]['is_replace'] = 0;
  331. }else{
  332. $data[$i]['is_replace'] = 1;
  333. $is_replace = 1;
  334. }
  335. $data[$i]['material'] = $formula[$i][0];
  336. $data[$i]['percentage'] = encrypt($formula[$i][1]);
  337. $data[$i]['gy_name'] = $formula[$i][2];
  338. $data[$i]['gy_num'] = $formula[$i][3];
  339. // $data[$i]['gy_num'] = $gy_num;
  340. $data[$i]['pid'] = $ids;
  341. $data[$i]['version'] = 'v'.$version;
  342. $data[$i]['create'] = date('Y-m-d H:i:s');
  343. }
  344. if ($isChange === true){
  345. Db::name('formula_detail')->insertAll($data);
  346. }
  347. //有替代料的话 查出所有替代料 然后分解 插入到数据库 //2022年9月19日14:19:09 替代料更改
  348. // if ($is_replace == 1 && ($materialChange == 1 || $change == 1)){
  349. // $replace = Db::name('formula_detail')->where('pid',$ids)->where('is_replace',1)->field('id,material')->select();
  350. // $replaceData = [];
  351. // $j = 0;
  352. // foreach ($replace as $k=>$v){
  353. // $material = explode('/',$v['material']);
  354. // for ($i=0;$i<count($material);$i++){
  355. // $replaceData[$j]['fid'] = $v['id'];
  356. // $replaceData[$j]['material'] = $material[$i];
  357. // $replaceData[$j]['create'] = date('Y-m-d H:i:s');
  358. // $j++;
  359. // }
  360. // }
  361. // $result = Db::name('formula_replace')->insertAll($replaceData);
  362. // }
  363. Db::commit();
  364. } catch (Exception $e) {
  365. Db::rollback();
  366. $this->error($e->getMessage());
  367. }
  368. if (false === $result) {
  369. $this->error(__('No rows were updated'));
  370. }
  371. $this->success();
  372. }
  373. //生成作业单
  374. public function task(){
  375. // $ceshi = Db::name('formula_detail')->where('id','>',52459)->limit(10000)->select();
  376. // foreach ($ceshi as $key=>$value){
  377. // $ceshi[$key]['percentage'] = encrypt($value['percentage']);
  378. // }
  379. // Db::name('formula_detail_c')->insertAll($ceshi);
  380. // print_r('-------------------------------');
  381. // die;
  382. $ids = input('ids');
  383. if (!$ids) {
  384. $this->error(__('No Results were found'));
  385. }
  386. if (false === $this->request->isPost()) {
  387. //生产部=>开票人
  388. $sckp = Db::name('personnel')->where('bid',"=",3)->where('position','=',"sckp")->order('name desc')->select();
  389. //生产部=>审核人
  390. $scsh = Db::name('personnel')->where('bid',"=",3)->where('position','=',"scsh")->order('name desc')->select();
  391. $this->assign('sckp',$sckp);
  392. $this->assign('scsh',$scsh);
  393. //批次号顺序新增
  394. $tastbach = Db::name('task')->order('bach desc')->find();
  395. $bach = $tastbach['bach'] +1;
  396. $this->view->assign('bach',$bach);
  397. $list = Db::name('formula')->where('id',$ids)->find();
  398. $list['gyinfo'] = Db::name('formula_detail')->where('pid',$ids)->where('version',$list['version'])->field('id,material,percentage,gy_name,gy_num')->select();
  399. foreach ($list['gyinfo'] as $key=>$value){
  400. $list['gyinfo'][$key]['percentage'] = decode($value['percentage']);
  401. }
  402. //新增关联订单
  403. $order = Db::name('order')->where('status','neq',3)->field('id,customer,product,number,completed')->select();
  404. $uncompleted_order = array();
  405. if (!empty($order)){
  406. foreach($order as $k=>$v){
  407. $uncompleted_order[$k]['id'] = $v['id'];
  408. if (empty($v['completed'])){
  409. $completed = 0;
  410. }else{
  411. $completed = $v['completed'];
  412. }
  413. $uncompleted_order[$k]['str'] = $v['id'].'、'.$v['customer'].'-'.$v['product'].'-'.'总数量('.$v['number'].'kg)'.'-' .'已完成('.$completed.'kg)';
  414. }
  415. }
  416. $this->view->assign('ids',$ids);
  417. $this->view->assign('order',$uncompleted_order);
  418. $this->view->assign('machineList',\app\admin\model\Machine::select());
  419. $this->view->assign('row', $list);
  420. return $this->view->fetch();
  421. }
  422. $base = $this->request->post('baseData/a');
  423. // print_r($base);die;
  424. if (empty($base)){
  425. $this->error('数据不能为空');
  426. }
  427. //基础数据
  428. $params = [];
  429. $params['fid'] = $base[0];
  430. $params['name'] = $base[1];
  431. $params['bach'] = $base[2];
  432. $params['drawer_name'] = $base[3];
  433. $params['examine_name'] = $base[4];
  434. $params['number'] = $base[5];
  435. $params['remark'] = $base[6];
  436. $params['machine'] = $base[7];
  437. $params['oid'] = $base[8];
  438. $params['create'] = date('Y-m-d H:i:s');
  439. $result = false;
  440. Db::startTrans();
  441. try {
  442. $result = Db::name('task')->insert($params);
  443. //更改订单已完成数量,修改订单状态
  444. $order_info = Db::name('order')->where('id',$params['oid'])->find();
  445. if (empty($order_info['completed'])){
  446. $new_completed = $params['number'];
  447. $order_status = 2;//生产中
  448. Db::name('order')->where('id',$params['oid'])->setField('status',2);
  449. }else{
  450. $new_completed = $params['number'] + $order_info['completed'];
  451. }
  452. Db::name('order')->where('id',$params['oid'])->setField('completed',$new_completed);
  453. Db::commit();
  454. } catch (Exception $e) {
  455. Db::rollback();
  456. $this->error($e->getMessage());
  457. }
  458. if (false === $result) {
  459. $this->error(__('No rows were updated'));
  460. }
  461. $this->success();
  462. }
  463. //配方审核列表
  464. public function examine(){
  465. //设置过滤方法
  466. $this->request->filter(['strip_tags', 'trim']);
  467. if (false === $this->request->isAjax()) {
  468. return $this->view->fetch();
  469. }
  470. //如果发送的来源是 Selectpage,则转发到 Selectpage
  471. if ($this->request->request('keyField')) {
  472. return $this->selectpage();
  473. }
  474. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  475. $user_info = Session::get('admin');
  476. $map = [];
  477. $map['examine_status'] = 1;
  478. if ($user_info['id'] !== 1){
  479. $map['company_id'] = $user_info['company_id'];
  480. }
  481. $list = $this->model
  482. ->where($where)
  483. ->where($map)
  484. ->order($sort, $order)
  485. ->paginate($limit);
  486. $result = ['total' => $list->total(), 'rows' => $list->items()];
  487. return json($result);
  488. }
  489. //审核操作
  490. public function status($ids=null){
  491. if (!$ids) {
  492. $this->error(__('No Results were found'));
  493. }
  494. if (false === $this->request->isPost()) {
  495. $list = Db::name('formula')->where('id',$ids)->find();
  496. //可用性,对应客户名称
  497. if ($list['usability'] != 99){
  498. $customer = explode(',',$list['usability']);
  499. $name = Db::name('customer')->where('id','in',$customer)->column('customer_name');
  500. }
  501. $list['gyinfo'] = Db::name('formula_detail')->where('pid',$ids)->where('version',$list['version'])->field('material,percentage,gy_name,gy_num')->select();
  502. foreach ($list['gyinfo'] as $key=>$value){
  503. $list['gyinfo'][$key]['percentage'] = decode($value['percentage']);
  504. }
  505. $this->view->assign('ids',$ids);
  506. $this->view->assign('name',$name);
  507. $this->view->assign('row', $list);
  508. return $this->view->fetch();
  509. }
  510. $status = $this->request->post('status');
  511. if (!isset($status) || !isset($ids)){
  512. $this->error('审核失败');
  513. }
  514. $params = [];
  515. $params['examine_status'] = $status;
  516. $params['update'] = date('Y-m-d H:i:s');
  517. $result = false;
  518. Db::startTrans();
  519. try {
  520. $list = Db::name('formula')->where('id',$ids)->find();
  521. if ($list['version'] == 'v0.1'){
  522. Db::name('formula')->where('id',$ids)->setField('version','v1.0');
  523. Db::name('formula_detail')->where('pid',$ids)->setField('version','v1.0');
  524. }
  525. $result = Db::name('formula')->where('id',$ids)->update($params);
  526. Db::commit();
  527. } catch (Exception $e) {
  528. Db::rollback();
  529. $this->error($e->getMessage());
  530. }
  531. if ($result){
  532. $this->success('更新成功');
  533. }else{
  534. $this->error('审核失败');
  535. }
  536. }
  537. //下拉选择获取客户列表
  538. public function getCustomer(){
  539. $user_info = Session::get('admin');
  540. $where = [];
  541. if ($user_info['id'] !== 1){
  542. $where['company_id'] =$user_info['company_id'];
  543. }
  544. $row = Db::name('customer')->where($where)->field('id,customer_name')->select();
  545. $result = ['total' => count($row), 'rows' => $row];
  546. return json($result);
  547. }
  548. //获取生产单应加量
  549. public function getNumber(){
  550. $params = input('');
  551. if ($params['ids'] == '' || $params['number'] == '' || !is_numeric($params['number'])){
  552. return array('status'=>0,'msg'=>'请求参数错误');
  553. }
  554. $list = Db::name('formula')->where('id',$params['ids'])->find();
  555. $gyinfo= Db::name('formula_detail')->where('pid',$params['ids'])->where('version',$list['version'])->field('id,material,percentage,gy_name,gy_num')->select();
  556. if (empty($gyinfo)){
  557. return array('status'=>0,'msg'=>'数据错误');
  558. }
  559. $total = Db::name('formula_detail')->where('pid',$params['ids'])->where('version',$list['version'])->column('percentage');
  560. if (empty($total)){
  561. return array('status'=>0,'msg'=>'数据错误');
  562. }
  563. foreach ($total as $k=>$v){
  564. $total[$k] = decode($v);
  565. }
  566. $num = array_sum($total);
  567. foreach ($gyinfo as $key=>$value){
  568. if($gyinfo[$key]['gy_name'] == null){//
  569. $gyinfo[$key]['gy_name'] = '';//
  570. }//
  571. $gyinfo[$key]['num'] = '';
  572. $gyinfo[$key]['percentage'] = decode($value['percentage']);
  573. if (!empty($value['percentage'])){
  574. // $gyinfo[$key]['num'] = number_format($gyinfo[$key]['percentage'] / $num * $params['number'],3);
  575. $number = ceil($gyinfo[$key]['percentage'] / $num * $params['number'] *1000);
  576. $gyinfo[$key]['num'] = number_format($number/1000,3);
  577. }
  578. }
  579. $date = date('Y/m/d');
  580. return array('status'=>1,'data'=>$gyinfo,'formula_no'=>$list['formula_no'],'date'=>$date);
  581. }
  582. //获取工艺说明
  583. public function gyName(){
  584. $params = input('gy_name');
  585. // print_r($params);die;
  586. if ($params){
  587. $list = Db::name('formula_detail')->where('gy_name','like','%'.$params.'%')->field('id,gy_name')->limit(20)->select();
  588. }else{
  589. $list = Db::name('formula_detail')->where('gy_name','neq','')->field('id,gy_name')->limit(20)->select();
  590. }
  591. $total = count($list);
  592. $result = ['total'=>$total,'rows'=>$list];
  593. // return array('status'=>1,'rows'=>$list);
  594. return json($result);
  595. }
  596. }