Product.php 51 KB

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