Product.php 46 KB

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