Product.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\EntrustLog;
  4. use app\common\controller\Api;
  5. use \think\Request;
  6. use \think\Db;
  7. /**
  8. * 产品管理接口
  9. */
  10. class Product extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 首页
  16. *
  17. */
  18. public function index()
  19. {
  20. $this->success('请求成功');
  21. }
  22. /**
  23. * 获取产品资料
  24. *
  25. * @ApiMethod GET
  26. *@param string custom_code
  27. *@param string limit
  28. *@param string page
  29. */
  30. public function getProduct(){
  31. if (Request::instance()->isGet() == false){
  32. $this->error('非法请求');
  33. }
  34. $params = Request::instance()->param();
  35. $limit = $params['limit'];
  36. if (!isset($limit)){
  37. $limit = 15;
  38. }
  39. if (!isset($pages)){
  40. $pages = 0;
  41. }else{
  42. $pages = ($params['page']-1) * $limit;
  43. }
  44. $total = 0;
  45. if (isset($params['custom_code']) && !empty($params['custom_code'])){
  46. $customCode = $params['custom_code'];
  47. $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
  48. rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
  49. FROM `产品_基本资料` WHERE `客户编号` = '{$customCode}' ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END,
  50. `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
  51. $total = db('产品_基本资料')->where('客户编号',$customCode)->count();
  52. }else{
  53. if (isset($params['search']) && !empty($params['search'])){
  54. $search = $params['search'];
  55. $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
  56. rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
  57. FROM `产品_基本资料` WHERE `产品名称` LIKE '%{$search}%' OR `产品编号` LIKE '%{$search}%' ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END,
  58. `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
  59. $total = db('产品_基本资料')->where('产品名称','like','%'.$search.'%')->count();
  60. }else{
  61. $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
  62. rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
  63. FROM `产品_基本资料` ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END,
  64. `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
  65. $total = db('产品_基本资料')->count();
  66. }
  67. }
  68. $list = Db::query($sql);
  69. foreach ($list as $key=>$value){
  70. $code = trim($value['产品编号']);
  71. $gd_sql = "SELECT `接单日期` FROM `工单_基本资料` WHERE `成品代号` = '{$code}' ORDER BY Uniqid DESC";
  72. $gdRes = Db::query($gd_sql);
  73. $list[$key]['receiveDate'] = '';
  74. if (!empty($gdRes)){
  75. $list[$key]['receiveDate'] = $gdRes[0]['接单日期'];
  76. }
  77. $gy_sql = "SELECT * FROM `产品_工艺资料` WHERE Gy0_cpdh = '{$code}'";
  78. $gyRes = Db::query($gy_sql);
  79. $list[$key]['gyData'] = '';
  80. if (empty($gyRes)){
  81. $list[$key]['gyData'] = '缺';
  82. }
  83. $yj_sql = "SELECT COUNT(*) as total FROM `产品_印件资料` WHERE `yj_cpdh` = '{$code}'";
  84. $yjRes = Db::query($yj_sql);
  85. $list[$key]['yjData'] = '无';
  86. if ($yjRes[0]['total'] > 0){
  87. $list[$key]['yjData'] = $yjRes[0]['total'];
  88. }
  89. }
  90. $data['data'] = $list;
  91. $data['total'] = $total;
  92. $this->success('请求成功',$data);
  93. }
  94. /**
  95. * 获取产品基础数据
  96. *
  97. * @ApiMethod POST
  98. *@param string product_code
  99. */
  100. public function getProductData(){
  101. if (Request::instance()->isGet() == false){
  102. $this->error('非法请求');
  103. }
  104. $params = Request::instance()->param();
  105. $code = $params['product_code'];
  106. if (!isset($code)){
  107. $this->error('参数不能为空');
  108. }
  109. $num = config('product_code_digit');
  110. //工艺资料
  111. $option['a.Gy0_cpdh'] = $code;
  112. $gy_field = 'rtrim(a.Gy0_方案) as 方案,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.gy0_gxmc) as gy0_gxmc,rtrim(a.Add_gxmc) as add_gxmc,a.Gy0_Ks,a.Gy0_ls,rtrim(a.工序备注) as 备注,
  113. a.工价系数,a.损耗系数,a.Gy0_Ms,a.人工检_正品板,a.人工检_次品板,a.人工检_废检,a.机检_正品板,a.机检_次品板,a.机检_废检,rtrim(a.Gy0_sbmc) as Gy0_sbmc,rtrim(a.Sys_id) as Sys_id,
  114. a.Sys_rq,a.Mod_rq,b.sys_rate0 as 基础损耗,b.sys_rate1 as 损耗率,a.UniqID';
  115. $gyRes = db('产品_工艺资料')->alias('a')
  116. ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
  117. ->where($option)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
  118. //印件资料
  119. $where['yj_cpdh'] = $code;
  120. $field = 'yj_yjno,rtrim(yj_yjdh) as yj_yjdh,yj_yjmc,rtrim(yj_zzdh) as yj_zzdh,rtrim(yj_zzmc) as yj_zzmc,rtrim(yj_tlgg) as yj_tlgg,
  121. rtrim(yj_klgg) as yj_klgg,yj_ks,yj_ls,rtrim(yj_desc) as yj_desc,rtrim(sys_id) as sys_id,sys_rq,mod_rq,UniqId';
  122. $yjRes = db('产品_印件资料')->where($where)->field($field)->select();
  123. //印版资料
  124. $filter['a.YB_Cpdh'] = $code;
  125. $yb_field = 'rtrim(a.YB_方案) as YB_方案,a.YB_Yjno,rtrim(a.存货编码) as 存货编码,a.考核印数,rtrim(a.Sys_id) as Sys_id,a.Mod_rq,rtrim(b.物料名称) as 印版名称,rtrim(c.名称) as 印版类别,a.UniqID';
  126. $ybRes = db('产品_印版资料')->alias('a')
  127. ->join('物料_存货编码 b','a.存货编码 = b.物料代码','left')
  128. ->join('物料_存货结构 c','LEFT(a.存货编码,'.$num.') = c.编号','left')
  129. ->where($filter)->field($yb_field)->order('a.YB_Yjno,a.存货编码')->select();
  130. //技术附件
  131. $jsRes = db('产品_技术附件')
  132. ->where('关联产品','like','%'.$code.'%')
  133. ->select();
  134. foreach ($jsRes as $key=>&$value){
  135. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  136. $value['附件内容'] = '';
  137. }
  138. }
  139. $list = [];
  140. $list['yjData'] = $yjRes;
  141. $list['gyData'] = $gyRes;
  142. $list['ybData'] = $ybRes;
  143. $list['jsData'] = $jsRes;
  144. $this->success('请求成功',$list);
  145. }
  146. /**
  147. * 4.获取单个工艺数据(排产参数调整)
  148. *
  149. * @ApiMethod GET
  150. *@param string product_code
  151. */
  152. public function getProductGy(){
  153. if (Request::instance()->isGet() == false){
  154. $this->error('非法请求');
  155. }
  156. $params = Request::instance()->param();
  157. $code = $params['product_code'];
  158. if (!isset($code)){
  159. $this->error('参数不能为空');
  160. }
  161. $option['a.Gy0_cpdh'] = $code;
  162. if (!empty($params['plan'])){
  163. $option['a.Gy0_方案'] = $params['plan'];
  164. }
  165. $gy_field = 'rtrim(a.Gy0_方案) as programme,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.gy0_gxmc) as gy0_gxmc,a.A类产能 as A_power,rtrim(a.Gy0_shdh) as Gy0_shdh,rtrim(a.Gy0_sbbh) as Gy0_sbbh,
  166. a.工价系数 as difficulty_coe,a.损耗系数 as loss_coe,a.Gy0_Ms as ms_coe,a.Gy0_Ks,a.Gy0_ls,rtrim(a.Gy0_site) as Gy0_site,rtrim(a.Add_gxmc) as Add_gxmc,a.UniqID,a.Gy0_辅助工时,
  167. rtrim(a.工序备注) as remark,a.人工检_正品板 as artificial_zp,a.人工检_次品板 as artificial_cp,a.人工检_废检 as artificial_fj,a.机检_正品板 as machine_zp,a.机检_次品板 as machine_cp,
  168. a.机检_废检 as machine_fj,rtrim(b.客户名称) as custom_name,rtrim(b.产品名称) as product_name,a.UniqId';
  169. $gyRes = db('产品_工艺资料')->alias('a')
  170. ->join('产品_基本资料 b','a.Gy0_cpdh = b.产品编号','left')
  171. ->where($option)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
  172. $this->success('请求成功',$gyRes);
  173. }
  174. /**
  175. * 修改工艺参数
  176. *
  177. * @ApiMethod
  178. * @params array data
  179. */
  180. public function editGy(){
  181. if (Request::instance()->isPost() == false){
  182. $this->error('非法请求');
  183. }
  184. $params = Request::instance()->post();
  185. if (!isset($params) || !isset($params[0]['UniqID'])){
  186. $this->error('参数不能为空');
  187. }
  188. $i = 0;
  189. foreach ($params as $key=>$value){
  190. $data = [];
  191. if (!empty($value['A_power'])){
  192. $data['A类产能'] = $value['A_power'];
  193. }
  194. if (!empty($value['shdh'])){
  195. $data['Gy0_shdh'] = $value['shdh'];
  196. }
  197. if (!empty($value['machine'])){
  198. $data['Gy0_sbbh'] = $value['machine'];
  199. }
  200. if (!empty($value['time'])){
  201. $data['Gy0_辅助工时'] = $value['time'];
  202. }
  203. if (!empty($value['difficulty_coe'])){
  204. $data['工价系数'] = $value['difficulty_coe'];
  205. }
  206. if (!empty($value['loss_coe'])){
  207. $data['损耗系数'] = $value['loss_coe'];
  208. }
  209. if (!empty($value['ms_coe'])){
  210. $data['Gy0_Ms'] = $value['ms_coe'];
  211. }
  212. $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
  213. $res = Db::query($sql);
  214. if ($res !== false){
  215. $i++;
  216. }
  217. }
  218. if ($i !== 0){
  219. $this->success('更新成功');
  220. }else{
  221. $this->error('更新失败');
  222. }
  223. }
  224. /**
  225. * 修改产品信息
  226. *
  227. * @ApiMethod POST
  228. *
  229. * @params object data
  230. */
  231. public function editProduct(){
  232. if (Request::instance()->isPost() == false){
  233. $this->error('非法请求');
  234. }
  235. $params = Request::instance()->post();
  236. if (empty($params)){
  237. $this->error('参数不能为空');
  238. }
  239. if (!isset($params['印品代号'])){
  240. $this->error('印品代号不能为空');
  241. }
  242. $code = $params['印品代号'];
  243. unset($params['印品代号']);
  244. $sql = db('产品_基本资料')->where('产品编号',$code)->fetchSql(true)->update($params);
  245. $res = Db::query($sql);
  246. if ($res !== false){
  247. $this->success('更新成功');
  248. }else{
  249. $this->error('更新失败');
  250. }
  251. }
  252. /**
  253. * 设置产品状态
  254. *
  255. * @ApiMethod POST
  256. * @params string status
  257. * @params string code
  258. */
  259. public function setProductStatus(){
  260. if (Request::instance()->isPost() == false){
  261. $this->error('非法请求');
  262. }
  263. $params = Request::instance()->post();
  264. if (empty($params['code']) || empty($params['status'])){
  265. $this->error('参数不能为空');
  266. }
  267. $code = $params['code'];
  268. $status = '';
  269. if ($params['status'] == 2){
  270. $status = '停产';
  271. }
  272. $sql = db('产品_基本资料')->where('产品编号',$code)->fetchSql(true)->setField('状态',$status);
  273. $res = Db::query($sql);
  274. if ($res !== false){
  275. $this->success('更新成功');
  276. }else{
  277. $this->error('更新失败');
  278. }
  279. }
  280. /**
  281. * 获取产品工艺数量
  282. *
  283. * @ApiMethod GET
  284. * @params string code
  285. */
  286. public function getGyTotal(){
  287. if (Request::instance()->isGet() == false){
  288. $this->error('非法请求');
  289. }
  290. $params = Request::instance()->param();
  291. $code = $params['code'];
  292. if (!isset($code)){
  293. $this->error('参数不能为空');
  294. }
  295. $res = db('产品_工艺资料')->where('Gy0_cpdh',$code)->distinct(true)->column('rtrim(Gy0_方案) as gy_plan');
  296. $data['gy'] = $res;
  297. $product = db('产品_基本资料')->where('产品编号',$code)->find();
  298. $data['name'] = rtrim($product['产品名称']);
  299. $this->success('请求成功',$data);
  300. }
  301. /**
  302. * 复制产品工艺信息
  303. *
  304. * @ApiMethod POST
  305. * @params string from_code
  306. * @params string from_pro
  307. * @params string to_code
  308. * @params string to_pro
  309. * @params int is_copy_gy
  310. */
  311. public function copyProductGy(){
  312. if (Request::instance()->isPost() == false){
  313. $this->error('非法请求');
  314. }
  315. $params = Request::instance()->post();
  316. if (empty($params['from_code']) || empty($params['from_pro']) || empty($params['to_code']) ){
  317. $this->error('参数不能为空');
  318. }
  319. if ($params['is_copy_gy'] == 1){
  320. if (empty($params['to_pro'])){
  321. $this->error('工艺方案不能为空');
  322. }
  323. //查出参考的工艺数据
  324. $where['Gy0_cpdh'] = $params['from_code'];
  325. $where['Gy0_方案'] = $params['from_pro'];
  326. $gyList = db('产品_工艺资料')->where($where)->select();
  327. if (empty($gyList)){
  328. $this->error('参考产品无工艺资料数据');
  329. }
  330. $UniqID = db('产品_工艺资料')->order('UniqID desc')->value('UniqID');
  331. foreach ($gyList as $key=>$value){
  332. unset($gyList[$key]['UniqID']);
  333. $UniqID ++;
  334. $gyList[$key]['Gy0_方案'] = $params['to_pro'];
  335. $gyList[$key]['Gy0_cpdh'] = $params['to_code'];
  336. $gyList[$key]['UniqID'] = $UniqID;
  337. }
  338. }
  339. if ($params['is_copy_yb'] == 1){
  340. $UniqId = db('产品_印版资料')->order('UniqID desc')->value('UniqID');
  341. $option['YB_Cpdh'] = $params['from_code'];
  342. $ybList = db('产品_印版资料')->where($option)->select();
  343. if (empty($ybList)){
  344. $this->error('参考产品无印版资料数据');
  345. }
  346. foreach ($ybList as $key=>$value){
  347. unset($ybList[$key]['UniqID']);
  348. $UniqId++;
  349. $ybList[$key]['YB_Cpdh'] = $params['to_code'];
  350. $ybList[$key]['UniqID'] = $UniqId;
  351. }
  352. }
  353. if ($params['is_copy_gy'] == 1 && $params['is_copy_yb'] == 1){
  354. $gyResult = db('产品_工艺资料')->insertAll($gyList);
  355. if (!$gyResult){
  356. $this->error('复制产品工艺资料数据失败');
  357. }
  358. $ybResult = db('产品_印版资料')->insertAll($ybList);
  359. if (!$ybResult){
  360. $this->error('复制产品印版资料数据失败');
  361. }
  362. }elseif ($params['is_copy_gy'] == 1 && $params['is_copy_yb'] == 0){
  363. $gyResult = db('产品_工艺资料')->insertAll($gyList);
  364. if (!$gyResult){
  365. $this->error('复制产品工艺资料数据失败');
  366. }
  367. }elseif ($params['is_copy_gy'] == 0 && $params['is_copy_yb'] == 1){
  368. $ybResult = db('产品_印版资料')->insertAll($ybList);
  369. if (!$ybResult){
  370. $this->error('复制产品印版资料数据失败');
  371. }
  372. }else{
  373. $this->success('工艺、印版至少选中一个');
  374. }
  375. $this->success('工艺复制成功');
  376. }
  377. /**
  378. * 工艺方案更名
  379. *
  380. * @ApiMethod POST
  381. * @params string code
  382. * @params string name
  383. */
  384. public function editGyName(){
  385. if (Request::instance()->isPost() == false){
  386. $this->error('非法请求');
  387. }
  388. $params = Request::instance()->post();
  389. if (empty($params['code']) || empty($params['old_name']) || empty($params['new_name'])){
  390. $this->error('参数不能为空');
  391. }
  392. $where['Gy0_cpdh'] = $params['code'];
  393. $where['Gy0_方案'] = $params['old_name'];
  394. $sql = db('产品_工艺资料')->where($where)->fetchSql(true)->setField('Gy0_方案',$params['new_name']);
  395. $res = Db::query($sql);
  396. if ($res !== false){
  397. $this->success('更新成功');
  398. }else{
  399. $this->error('更新失败');
  400. }
  401. }
  402. /**
  403. * 工艺方案附加
  404. *
  405. * @ApiMethod POST
  406. * @params object data
  407. */
  408. public function editGyNo(){
  409. if (Request::instance()->isPost() == false){
  410. $this->error('非法请求');
  411. }
  412. $params = Request::instance()->post();
  413. if (empty($params) || !isset($params[0]['UniqID'])){
  414. $this->error('参数不能为空');
  415. }
  416. $i = 0;
  417. foreach ($params as $key=>$value){
  418. $data = [];
  419. if (!empty($value['Gy0_yjno'])){
  420. $data['Gy0_yjno'] = $value['Gy0_yjno'];
  421. }
  422. if (!empty($value['Gy0_gxh'])){
  423. $data['Gy0_gxh'] = $value['Gy0_gxh'];
  424. }
  425. if (!empty($value['Gy0_Ks'])){
  426. $data['Gy0_Ks'] = $value['Gy0_Ks'];
  427. }
  428. if (!empty($value['Gy0_ls'])){
  429. $data['Gy0_ls'] = $value['Gy0_ls'];
  430. }
  431. $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
  432. $res = Db::query($sql);
  433. if ($res !== false){
  434. $i++;
  435. }
  436. }
  437. if ($i !== 0){
  438. $this->success('更新成功');
  439. }else{
  440. $this->error('更新失败');
  441. }
  442. }
  443. /**
  444. * 计损色数修正
  445. *
  446. * @ApiMethod POST
  447. * @params object data
  448. */
  449. public function editGyMs(){
  450. if (Request::instance()->isPost() == false){
  451. $this->error('非法请求');
  452. }
  453. $params = Request::instance()->post();
  454. if (empty($params) || !isset($params[0]['UniqID'])){
  455. $this->error('参数不能为空');
  456. }
  457. $i = 0;
  458. foreach ($params as $key=>$value){
  459. $data = [];
  460. if (!empty($value['Gy0_Ms'])){
  461. $data['Gy0_Ms'] = $value['Gy0_Ms'];
  462. }
  463. if (!empty($value['Gy0_Ks'])){
  464. $data['Gy0_Ks'] = $value['Gy0_Ks'];
  465. }
  466. if (!empty($value['Gy0_ls'])){
  467. $data['Gy0_ls'] = $value['Gy0_ls'];
  468. }
  469. $data['Add_gxmc'] = $value['Add_gxmc'];
  470. $data['工序备注'] = $value['remark'];
  471. $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
  472. $res = Db::query($sql);
  473. if ($res !== false){
  474. $i++;
  475. }
  476. }
  477. if ($i !== 0){
  478. $this->success('更新成功');
  479. }else{
  480. $this->error('更新失败');
  481. }
  482. }
  483. /**
  484. * 产品质检废品系数调整
  485. *
  486. * @ApiMethod POST
  487. * @params object data
  488. */
  489. public function editGyWaste(){
  490. if (Request::instance()->isPost() == false){
  491. $this->error('非法请求');
  492. }
  493. $params = Request::instance()->post();
  494. if (empty($params) || !isset($params[0]['UniqID'])){
  495. $this->error('参数不能为空');
  496. }
  497. $i = 0;
  498. foreach ($params as $key=>$value){
  499. $data = [];
  500. if (!empty($value['artificial_zp'])){
  501. $data['人工检_正品板'] = $value['artificial_zp'];
  502. }
  503. if (!empty($value['artificial_cp'])){
  504. $data['人工检_次品板'] = $value['artificial_cp'];
  505. }
  506. if (!empty($value['artificial_fj'])){
  507. $data['人工检_废检'] = $value['artificial_fj'];
  508. }
  509. if (!empty($value['machine_zp'])){
  510. $data['机检_正品板'] = $value['machine_zp'];
  511. }
  512. if (!empty($value['machine_cp'])){
  513. $data['机检_次品板'] = $value['machine_cp'];
  514. }
  515. if (!empty($value['machine_fj'])){
  516. $data['机检_废检'] = $value['machine_fj'];
  517. }
  518. $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
  519. $res = Db::query($sql);
  520. if ($res !== false){
  521. $i++;
  522. }
  523. }
  524. if ($i !== 0){
  525. $this->success('更新成功');
  526. }else{
  527. $this->error('更新失败');
  528. }
  529. }
  530. /**
  531. * 获取产品印件资料
  532. * @ApiMethod GET
  533. * @params string UniqId
  534. */
  535. public function getProductYjInfo(){
  536. if (Request::instance()->isGet() == false){
  537. $this->error('非法请求');
  538. }
  539. $params = Request::instance()->param();
  540. if (empty($params['UniqId']) || empty($params['UniqId'])){
  541. $this->error('参数错误');
  542. }
  543. $field = "yj_yjno,rtrim(yj_yjdh) as yj_yjdh,rtrim(yj_yjmc) as yj_yjmc,rtrim(yj_zzdh) as yj_zzdh,rtrim(yj_zzmc) as yj_zzmc,rtrim(yj_zzdh1) as yj_zzdh1,rtrim(yj_zzdh2) as yj_zzdh2,
  544. rtrim(yj_zzdh3) as yj_zzdh3,rtrim(yj_zzdh4) as yj_zzdh4,rtrim(yj_zzmc1) as yj_zzmc1,rtrim(yj_zzmc2) as yj_zzmc2,rtrim(yj_zzmc3) as yj_zzmc3,
  545. rtrim(yj_zzmc4) as yj_zzmc4,rtrim(yj_tlgg) as yj_tlgg,rtrim(yj_klgg) as yj_klgg,yj_ks,yj_ls,KgToPages,rtrim(yj_desc) as yj_desc,UniqId";
  546. $list = \db('产品_印件资料')->where('UniqId',$params['UniqId'])->field($field)->select();
  547. $this->success('请求成功',$list);
  548. }
  549. /**
  550. * 修改产品印件资料
  551. * @ApiMethod POST
  552. * @params array data
  553. */
  554. public function editProductYjInfo(){
  555. if (Request::instance()->isPost() == false){
  556. $this->error('非法请求');
  557. }
  558. $params = Request::instance()->post();
  559. if (empty($params) || !isset($params['UniqId'])){
  560. $this->error('参数不能为空');
  561. }
  562. $UniqId = $params['UniqId'];
  563. unset($params['UniqId']);
  564. $res = \db('产品_印件资料')->where('UniqId',$UniqId)->update($params);
  565. if ($res !== false){
  566. $this->success('更新成功');
  567. }else{
  568. $this->error('更新失败');
  569. }
  570. }
  571. /**
  572. * 新增产品印件资料
  573. * @ApiMethod POST
  574. * @params array data
  575. */
  576. public function addProductYjInfo(){
  577. if (Request::instance()->isPost() == false){
  578. $this->error('非法请求');
  579. }
  580. $params = Request::instance()->post();
  581. $UniqId = \db('产品_印件资料')->order('UniqId desc')->value('UniqId');
  582. if ($UniqId < 2000000){
  583. $UniqId = 2000000;
  584. }else{
  585. $UniqId = $UniqId + 1;
  586. }
  587. $params['UniqId'] = $UniqId;
  588. $params['sys_rq'] = date('Y-m-d H:i:s');
  589. $res = \db('产品_印件资料')->insert($params);
  590. if ($res !== false){
  591. $this->success('新增成功');
  592. }else{
  593. $this->error('新增失败');
  594. }
  595. }
  596. /**
  597. * 获取印件代码及名称
  598. * @ApiMethod GET
  599. *
  600. */
  601. public function getProductYjList(){
  602. if (Request::instance()->isGet() == false){
  603. $this->error('非法请求');
  604. }
  605. $params = Request::instance()->get();
  606. $search = $params['search'];
  607. $num = config('product_code_digit');
  608. if (!empty($search)){
  609. $sql = "SELECT DISTINCT rtrim(a.`物料代码`) AS `物料代码`,rtrim(a.`物料名称`) AS `物料名称`,rtrim(b.`客户编号`) AS `客户编号`,rtrim(b.`客户名称`) AS `客户名称` FROM
  610. `物料_存货编码` a
  611. JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
  612. WHERE a.`物料名称` LIKE '%{$search}%' or a.物料代码 LIKE '%{$search}%'
  613. ORDER BY a.`物料代码` ASC";
  614. }else{
  615. $sql = "SELECT DISTINCT rtrim(a.`物料代码`) as `物料代码`, rtrim(a.`物料名称`) as `物料名称`,rtrim(b.客户编号) as 客户编号,rtrim(b.客户名称) as 客户名称
  616. FROM `物料_存货编码` a
  617. JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
  618. ORDER BY a.`物料代码` ASC";
  619. }
  620. // halt($sql);
  621. $data = Db::query($sql);
  622. // 初始化一个关联数组,用于存储相同客户编号的数据
  623. $groupedData = [];
  624. foreach ($data as $row) {
  625. $customerCode = substr($row['物料代码'],0,$num).substr($row['客户编号'],2,2).'/'.$row['客户名称'];
  626. $materialCodePrefix = substr($row['物料代码'], 0, $num);
  627. if ($materialCodePrefix == 'Y1401' ){
  628. $materialCodePrefix = $materialCodePrefix.'/糊盒类产品(含贴码)';
  629. }else{
  630. $materialCodePrefix = $materialCodePrefix.'/直接领用产品';
  631. }
  632. // 如果关联数组中不存在该物料代码前四位的键,则创建一个空数组
  633. if (!isset($groupedData[$materialCodePrefix])) {
  634. $groupedData[$materialCodePrefix] = [];
  635. }
  636. // 如果物料代码前四位数组中不存在该客户编号的键,则创建一个空数组
  637. if (!isset($groupedData[$materialCodePrefix][$customerCode])) {
  638. $groupedData[$materialCodePrefix][$customerCode] = [];
  639. }
  640. // 去除客户编号和客户名称
  641. unset($row['客户编号']);
  642. unset($row['客户名称']);
  643. // 将当前行的数据添加到相应的物料代码前四位和客户编号的数组中
  644. $groupedData[$materialCodePrefix][$customerCode][] = $row;
  645. }
  646. $this->success('请求成功',$groupedData);
  647. }
  648. /**
  649. * 获取纸张代号及名称
  650. * @ApiMethod GET
  651. * @params string search
  652. */
  653. public function getProductZzList(){
  654. if (Request::instance()->isGet() == false){
  655. $this->error('非法请求');
  656. }
  657. $params = Request::instance()->get();
  658. $search = $params['search'];
  659. $num = config('product_code_digit');
  660. if (!empty($search)){
  661. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
  662. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  663. FROM `物料_存货编码` a
  664. LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
  665. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  666. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  667. WHERE a.物料名称 LIKE '%{$search}%' AND (a.物料代码 LIKE 'J00%' or a.物料代码 LIKE 'J01%' or a.物料代码 LIKE 'J30%')";
  668. }else{
  669. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
  670. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  671. FROM `物料_存货编码` a
  672. LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
  673. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  674. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  675. WHERE a.物料代码 LIKE 'J00%' or a.物料代码 LIKE 'J01%' or a.物料代码 LIKE 'J30%'";
  676. }
  677. $data = Db::query($sql);
  678. $mergedArray = [];
  679. foreach ($data as $item) {
  680. $oneCode = $item['oneCode'];
  681. $twoCode = $item['twoCode'];
  682. $thrCode = $item['thrCode'];
  683. $oneName = $item['oneName'];
  684. $twoName = $item['twoName'];
  685. $thrName = $item['thrName'];
  686. // Create a unique key using the combination of oneCode, twoCode, and thrCode
  687. $oneKey = "{$oneCode}/{$oneName}";
  688. $twoKey = "{$twoCode}/{$twoName}";
  689. $thrKey = "{$thrCode}/{$thrName}";
  690. // Initialize arrays if not already set
  691. if (!isset($mergedArray[$oneKey])) {
  692. $mergedArray[$oneKey] = [];
  693. }
  694. if (!isset($mergedArray[$oneKey][$twoKey])) {
  695. $mergedArray[$oneKey][$twoKey] = [];
  696. }
  697. // Append items to the arrays
  698. $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
  699. }
  700. $this->success('请求成功',$mergedArray);
  701. }
  702. /**
  703. *3.6工艺资料-获取产品工艺资料
  704. */
  705. public function getProductGyInfo(){
  706. if (Request::instance()->isGet() == false){
  707. $this->error('非法请求');
  708. }
  709. $params = Request::instance()->param();
  710. if (empty($params['UniqID']) || empty($params['UniqID'])){
  711. $this->error('参数错误');
  712. }
  713. $field = "rtrim(a.Gy0_方案) as Gy0_方案,a.Gy0_yjno,a.Gy0_gxh,a.Gy0_Ks,a.Gy0_ls,rtrim(a.Gy0_site) as Gy0_site,rtrim(a.gy0_gxmc) as gy0_gxmc,rtrim(a.Add_gxmc) as Add_gxmc,a.Gy0_Ms,
  714. rtrim(a.Gy0_sbbh) as Gy0_sbbh,rtrim(a.Gy0_shdh) as Gy0_shdh,rtrim(b.sys_mc) as sys_mc,b.sys_rate0,b.sys_rate1,a.工价系数,a.损耗系数,rtrim(a.工序备注) as 工序备注,
  715. rtrim(a.质量要求) as 质量要求,rtrim(a.质量隐患) as 质量隐患,a.UniqID";
  716. $data = \db('产品_工艺资料')->alias('a')
  717. ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
  718. ->where('a.UniqID',$params['UniqID'])
  719. ->field($field)
  720. ->find();
  721. $this->success('请求成功',$data);
  722. }
  723. /**
  724. * 3.7工艺资料-获取车间及工艺名称
  725. * @ApiMethod GET
  726. *
  727. */
  728. public function getDepartName(){
  729. if (Request::instance()->isGet() == false){
  730. $this->error('非法请求');
  731. }
  732. $data = \db('erp_常用字典')->where('分类','印刷工艺')->order('编号 asc')->column('名称');
  733. $resultArray = [];
  734. foreach ($data as $item) {
  735. $parts = explode('_', $item);
  736. // 使用第一个部分作为一级键,第二个部分作为二级键
  737. $firstKey = $parts[0];
  738. $secondKey = $parts[1];
  739. $thirdValue = $parts[2];
  740. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  741. }
  742. $this->success('请求成功',$resultArray);
  743. }
  744. /**
  745. * 3.8工艺资料-新增产品工艺
  746. */
  747. public function addProductGyInfo(){
  748. if (Request::instance()->isPost() == false){
  749. $this->error('非法请求');
  750. }
  751. $params = Request::instance()->post();
  752. $UniqId = \db('产品_工艺资料')->order('UniqID desc')->value('UniqID');
  753. if ($UniqId < 2000000){
  754. $UniqId = 2000000;
  755. }else{
  756. $UniqId = $UniqId + 1;
  757. }
  758. $params['UniqID'] = $UniqId;
  759. $params['Sys_rq'] = date('Y-m-d H:i:s');
  760. $sql = \db('产品_工艺资料')->fetchSql(true)->insert($params);
  761. $res = Db::query($sql);
  762. if ($res !== false){
  763. $this->success('新增成功');
  764. }else{
  765. $this->error('新增失败');
  766. }
  767. }
  768. /**
  769. * 3.9印版资料-获取产品印版资料
  770. * @ApiMethod GET
  771. */
  772. public function getProductYbInfo(){
  773. if (Request::instance()->isGet() == false){
  774. $this->error('非法请求');
  775. }
  776. $params = Request::instance()->param();
  777. if (empty($params['UniqID']) || empty($params['UniqID'])){
  778. $this->error('参数错误');
  779. }
  780. $field = "rtrim(a.YB_方案) as YB_方案,a.YB_Yjno,a.YB_gxh,rtrim(a.存货编码) as 存货编码,rtrim(a.印版名称) as 印版名称,a.UniqID,rtrim(b.gy0_gxmc) as gy0_gxmc,
  781. rtrim(b.Add_gxmc) as Add_gxmc,rtrim(c.物料名称) as 物料名称,rtrim(a.YB_cpdh) as YB_cpdh";
  782. $data = \db('产品_印版资料')->alias('a')
  783. ->join('产品_工艺资料 b','a.YB_cpdh = b.Gy0_cpdh and a.YB_Yjno = b.Gy0_yjno and a.YB_gxh = b.Gy0_gxh','left')
  784. ->join('物料_存货编码 c','a.存货编码 = c.物料代码','left')
  785. ->where('a.UniqID',$params['UniqID'])->field($field)->order('存货编码')->find();
  786. $where['Gy0_site'] = [
  787. ['like','胶印%'],
  788. ['like','烫模%'],
  789. 'or'
  790. ];
  791. $option['Gy0_cpdh'] = $data['YB_cpdh'];
  792. $option['Gy0_gxh'] = ['<',10];
  793. $option['Gy0_sbbh'] = ['neq',''];
  794. $gyData = \db('产品_工艺资料')->where($option)->where($where)
  795. ->field('rtrim(Gy0_方案) as Gy0_方案,Gy0_yjno,Gy0_gxh,rtrim(gy0_gxmc) as gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')
  796. ->order('Gy0_yjno,Gy0_gxh')->select();
  797. $list = [];
  798. foreach ($gyData as $key=>$value){
  799. $yjno = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  800. $gxh = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  801. $list[$key]['gy'] = $value['Gy0_方案'].'-->'.$yjno.'-'.$gxh.' '.$value['gy0_gxmc'];
  802. $list[$key]['gxmc'] = $value['Add_gxmc'];
  803. }
  804. $data['gy_data'] = $list;
  805. $this->success('请求成功',$data);
  806. }
  807. /**
  808. * 3.10印版资料-修改产品印版资料
  809. * @ApiMethod POST
  810. * @params string UniqId
  811. */
  812. public function editProductYbInfo(){
  813. if (Request::instance()->isPost() == false){
  814. $this->error('非法请求');
  815. }
  816. $params = Request::instance()->post();
  817. if (empty($params) || !isset($params['UniqId'])){
  818. $this->error('参数不能为空');
  819. }
  820. $UniqId = $params['UniqId'];
  821. unset($params['UniqId']);
  822. $sql = \db('产品_印版资料')->where('UniqId',$UniqId)->fetchSql(true)->update($params);
  823. $res = Db::query($sql);
  824. if ($res !== false){
  825. $this->success('更新成功');
  826. }else{
  827. $this->error('更新失败');
  828. }
  829. }
  830. /**
  831. * 印版资料-获取物料名称
  832. * @ApiMethod GET
  833. *
  834. */
  835. public function getProductYbMaterialList(){
  836. if (Request::instance()->isGet() == false){
  837. $this->error('非法请求');
  838. }
  839. $sql = "SELECT rtrim(`编号`) as 编号, rtrim(`名称`) as 名称 FROM `物料_存货结构` WHERE `编号` IN ('0502','0503','0510','0511','0512','0513','0514','0520','0521','0523','0524','0525')";
  840. $data = Db::query($sql);
  841. $this->success('请求成功',$data);
  842. }
  843. /**
  844. *3.12印版资料-获取详细存货名称
  845. * @ApiMethod GET
  846. * @params string code
  847. */
  848. public function getProductYbMaterialDetail(){
  849. if (Request::instance()->isGet() == false){
  850. $this->error('非法请求');
  851. }
  852. $params = Request::instance()->get();
  853. if (empty($params) || !isset($params['code'])){
  854. $this->error('参数不能为空');
  855. }
  856. $code = $params['code'];
  857. $search = $params['search'];
  858. $num = config('product_code_digit');
  859. if (!empty($search)){
  860. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
  861. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  862. FROM `物料_存货编码` a
  863. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  864. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  865. WHERE a.物料代码 LIKE '{$code}%' AND a.物料名称 LIKE '%{$search}%'";
  866. }else{
  867. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
  868. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  869. FROM `物料_存货编码` a
  870. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  871. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  872. WHERE a.物料代码 LIKE '{$code}%'";
  873. }
  874. $data = Db::query($sql);
  875. $mergedArray = [];
  876. foreach ($data as $item) {
  877. $oneCode = '05';
  878. $twoCode = $item['twoCode'];
  879. $thrCode = $item['thrCode'];
  880. $oneName = '版材';
  881. $twoName = $item['twoName'];
  882. $thrName = $item['thrName'];
  883. $oneKey = "{$oneCode}/{$oneName}";
  884. $twoKey = "{$twoCode}/{$twoName}";
  885. $thrKey = "{$thrCode}/{$thrName}";
  886. if (!isset($mergedArray[$oneKey])) {
  887. $mergedArray[$oneKey] = [];
  888. }
  889. if (!isset($mergedArray[$oneKey][$twoKey])) {
  890. $mergedArray[$oneKey][$twoKey] = [];
  891. }
  892. $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
  893. }
  894. $this->success('请求成功',$mergedArray);
  895. }
  896. /**
  897. * 3.13印版资料-新增产品印版资料
  898. * @ApiMethod POST
  899. * @params array data
  900. */
  901. public function addProductYbInfo(){
  902. if (Request::instance()->isPost() == false){
  903. $this->error('非法请求');
  904. }
  905. $params = Request::instance()->post();
  906. $UniqId = \db('产品_印版资料')->order('UniqID desc')->value('UniqID');
  907. if ($UniqId < 2000000){
  908. $UniqId = 2000000;
  909. }else{
  910. $UniqId = $UniqId + 1;
  911. }
  912. $params['UniqID'] = $UniqId;
  913. $params['考核印数'] = '0.00';
  914. $params['Sys_rq'] = date('Y-m-d H:i:s');
  915. $sql = \db('产品_印版资料')->fetchSql(true)->insert($params);
  916. $res = Db::query($sql);
  917. if ($res !== false){
  918. $this->success('新增成功');
  919. }else{
  920. $this->error('新增失败');
  921. }
  922. }
  923. }