Product.php 49 KB

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