Product.php 49 KB

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