Product.php 49 KB

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