Product.php 38 KB

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