Product.php 47 KB

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