Product.php 51 KB

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