Product.php 47 KB

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