Product.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  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['workshop'])){
  232. $data['Gy0_site'] = $value['workshop'];
  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. $num=5;
  649. if (!empty($search)){
  650. $sql = "SELECT DISTINCT rtrim(a.`物料代码`) AS `物料代码`,rtrim(a.`物料名称`) AS `物料名称`,rtrim(b.`客户编号`) AS `客户编号`,rtrim(b.`客户名称`) AS `客户名称` FROM
  651. `物料_存货编码` a
  652. JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
  653. WHERE (a.`物料名称` LIKE '%{$search}%' or a.物料代码 LIKE '%{$search}%')
  654. ORDER BY a.`物料代码` ASC";
  655. }else{
  656. $sql = "SELECT DISTINCT rtrim(a.`物料代码`) as `物料代码`, rtrim(a.`物料名称`) as `物料名称`,rtrim(b.客户编号) as 客户编号,rtrim(b.客户名称) as 客户名称
  657. FROM `物料_存货编码` a
  658. JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
  659. ORDER BY a.`物料代码` ASC";
  660. }
  661. $data = Db::query($sql);
  662. // 初始化一个关联数组,用于存储相同客户编号的数据
  663. $groupedData = [];
  664. foreach ($data as $row) {
  665. $customerCode = substr($row['物料代码'],0,$num).substr($row['客户编号'],2,2).'/'.$row['客户名称'];
  666. $materialCodePrefix = substr($row['物料代码'], 0, $num);
  667. if ($materialCodePrefix == 'Y1401' ){
  668. $materialCodePrefix = $materialCodePrefix.'/糊盒类产品(含贴码)';
  669. }else{
  670. $materialCodePrefix = $materialCodePrefix.'/直接领用产品';
  671. }
  672. // 如果关联数组中不存在该物料代码前四位的键,则创建一个空数组
  673. if (!isset($groupedData[$materialCodePrefix])) {
  674. $groupedData[$materialCodePrefix] = [];
  675. }
  676. // 如果物料代码前四位数组中不存在该客户编号的键,则创建一个空数组
  677. if (!isset($groupedData[$materialCodePrefix][$customerCode])) {
  678. $groupedData[$materialCodePrefix][$customerCode] = [];
  679. }
  680. // 去除客户编号和客户名称
  681. unset($row['客户编号']);
  682. unset($row['客户名称']);
  683. // 将当前行的数据添加到相应的物料代码前四位和客户编号的数组中
  684. $groupedData[$materialCodePrefix][$customerCode][] = $row;
  685. }
  686. $this->success('请求成功',$groupedData);
  687. }
  688. /**
  689. * 获取纸张代号及名称
  690. * @ApiMethod GET
  691. * @params string search
  692. */
  693. public function getProductZzList(){
  694. if (Request::instance()->isGet() == false){
  695. $this->error('非法请求');
  696. }
  697. $params = Request::instance()->get();
  698. $search = $params['search'];
  699. $num = config('product_code_digit');
  700. if (!empty($search)){
  701. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
  702. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  703. FROM `物料_存货编码` a
  704. LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
  705. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  706. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  707. WHERE (a.物料名称 LIKE '%{$search}%' or a.物料代码 LIKE '%{$search}%') and
  708. (a.物料代码 LIKE 'Y00%' or a.物料代码 LIKE 'Y01%' or a.物料代码 LIKE 'Y04%' or a.物料代码 LIKE 'J03%' or a.物料代码 LIKE 'Y14%')";
  709. $data = Db::query($sql);
  710. }else{
  711. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
  712. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  713. FROM `物料_存货编码` a
  714. LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
  715. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  716. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  717. WHERE a.物料代码 LIKE 'Y00%' or a.物料代码 LIKE 'Y01%' or a.物料代码 LIKE 'Y04%' or a.物料代码 LIKE 'J03%' or a.物料代码 LIKE 'Y14%'";
  718. $data = Db::query($sql);
  719. }
  720. $mergedArray = [];
  721. foreach ($data as $item) {
  722. $oneCode = $item['oneCode'];
  723. $twoCode = $item['twoCode'];
  724. $thrCode = $item['thrCode'];
  725. $oneName = $item['oneName'];
  726. $twoName = $item['twoName'];
  727. $thrName = $item['thrName'];
  728. // Create a unique key using the combination of oneCode, twoCode, and thrCode
  729. $oneKey = "{$oneCode}/{$oneName}";
  730. $twoKey = "{$twoCode}/{$twoName}";
  731. $thrKey = "{$thrCode}/{$thrName}";
  732. // Initialize arrays if not already set
  733. if (!isset($mergedArray[$oneKey])) {
  734. $mergedArray[$oneKey] = [];
  735. }
  736. if (!isset($mergedArray[$oneKey][$twoKey])) {
  737. $mergedArray[$oneKey][$twoKey] = [];
  738. }
  739. // Append items to the arrays
  740. $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
  741. }
  742. $this->success('请求成功',$mergedArray);
  743. }
  744. /**
  745. *3.6工艺资料-获取产品工艺资料
  746. */
  747. public function getProductGyInfo(){
  748. if (Request::instance()->isGet() == false){
  749. $this->error('非法请求');
  750. }
  751. $params = Request::instance()->param();
  752. if (empty($params['UniqID']) || empty($params['UniqID'])){
  753. $this->error('参数错误');
  754. }
  755. $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,
  756. 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 工序备注,
  757. rtrim(a.质量要求) as 质量要求,rtrim(a.质量隐患) as 质量隐患,a.UniqID";
  758. $data = \db('产品_工艺资料')->alias('a')
  759. ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
  760. ->where('a.UniqID',$params['UniqID'])
  761. ->field($field)
  762. ->find();
  763. $this->success('请求成功',$data);
  764. }
  765. /**
  766. * 3.7工艺资料-获取车间及工艺名称
  767. * @ApiMethod GET
  768. *
  769. */
  770. public function getDepartName(){
  771. if (Request::instance()->isGet() == false){
  772. $this->error('非法请求');
  773. }
  774. $param = $this->request->param();
  775. $data = \db('erp_常用字典')->where('分类','印刷工艺')->order('编号 asc')->column('名称');
  776. $resultArray = [];
  777. foreach ($data as $item) {
  778. $parts = explode('_', $item);
  779. // 使用第一个部分作为一级键,第二个部分作为二级键
  780. $firstKey = $parts[0];
  781. $secondKey = $parts[1];
  782. $thirdValue = $parts[2];
  783. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  784. }
  785. if (isset($param['sort'])){
  786. $result['标准工艺']['智能车间'] = $resultArray['标准工艺']['智能车间'];
  787. }else{
  788. unset($resultArray['标准工艺']['智能车间']);
  789. $result = $resultArray;
  790. }
  791. $this->success('请求成功',$result);
  792. }
  793. /**
  794. * 3.8工艺资料-新增产品工艺
  795. */
  796. public function addProductGyInfo(){
  797. if (Request::instance()->isPost() == false){
  798. $this->error('非法请求');
  799. }
  800. $params = Request::instance()->post();
  801. $UniqId = \db('产品_工艺资料')->order('UniqID desc')->value('UniqID');
  802. if ($UniqId < 2000000){
  803. $UniqId = 2000000;
  804. }else{
  805. $UniqId = $UniqId + 1;
  806. }
  807. $params['UniqID'] = $UniqId;
  808. $params['Sys_rq'] = date('Y-m-d H:i:s');
  809. $sql = \db('产品_工艺资料')->fetchSql(true)->insert($params);
  810. $res = Db::query($sql);
  811. if ($res !== false){
  812. $this->success('新增成功');
  813. }else{
  814. $this->error('新增失败');
  815. }
  816. }
  817. /**
  818. * 3.9印版资料-获取产品印版资料
  819. * @ApiMethod GET
  820. */
  821. public function getProductYbInfo(){
  822. if (Request::instance()->isGet() == false){
  823. $this->error('非法请求');
  824. }
  825. $params = Request::instance()->param();
  826. if (empty($params['UniqID']) || empty($params['UniqID'])){
  827. $this->error('参数错误');
  828. }
  829. $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,
  830. rtrim(b.Add_gxmc) as Add_gxmc,rtrim(c.物料名称) as 物料名称,rtrim(a.YB_cpdh) as YB_cpdh";
  831. $data = \db('产品_印版资料')->alias('a')
  832. ->join('产品_工艺资料 b','a.YB_cpdh = b.Gy0_cpdh and a.YB_Yjno = b.Gy0_yjno and a.YB_gxh = b.Gy0_gxh','left')
  833. ->join('物料_存货编码 c','a.存货编码 = c.物料代码','left')
  834. ->where('a.UniqID',$params['UniqID'])->field($field)->order('存货编码')->find();
  835. if (empty($data)){
  836. $this->error('未查询到产品印版资料');
  837. }
  838. $where['Gy0_site'] = [
  839. ['like','胶印%'],
  840. ['like','烫模%'],
  841. 'or'
  842. ];
  843. $option['Gy0_cpdh'] = $data['YB_cpdh'];
  844. $option['Gy0_gxh'] = ['<',10];
  845. $option['Gy0_sbbh'] = ['neq',''];
  846. $gyData = \db('产品_工艺资料')->where($option)->where($where)
  847. ->field('rtrim(Gy0_方案) as Gy0_方案,Gy0_yjno,Gy0_gxh,rtrim(gy0_gxmc) as gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')
  848. ->order('Gy0_yjno,Gy0_gxh')->select();
  849. $list = [];
  850. foreach ($gyData as $key=>$value){
  851. $yjno = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  852. $gxh = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  853. $list[$key]['gy'] = $value['Gy0_方案'].'-->'.$yjno.'-'.$gxh.' '.$value['gy0_gxmc'];
  854. $list[$key]['gxmc'] = $value['Add_gxmc'];
  855. }
  856. $data['gy_data'] = $list;
  857. $this->success('请求成功',$data);
  858. }
  859. /**
  860. * 3.10印版资料-修改产品印版资料
  861. * @ApiMethod POST
  862. * @params string UniqId
  863. */
  864. public function editProductYbInfo(){
  865. if (Request::instance()->isPost() == false){
  866. $this->error('非法请求');
  867. }
  868. $params = Request::instance()->post();
  869. if (empty($params) || !isset($params['UniqId'])){
  870. $this->error('参数不能为空');
  871. }
  872. $UniqId = $params['UniqId'];
  873. unset($params['UniqId']);
  874. $sql = \db('产品_印版资料')->where('UniqId',$UniqId)->fetchSql(true)->update($params);
  875. $res = Db::query($sql);
  876. if ($res !== false){
  877. $this->success('更新成功');
  878. }else{
  879. $this->error('更新失败');
  880. }
  881. }
  882. /**
  883. * 印版资料-获取物料名称
  884. * @ApiMethod GET
  885. *
  886. */
  887. public function getProductYbMaterialList(){
  888. if (Request::instance()->isGet() == false){
  889. $this->error('非法请求');
  890. }
  891. $sql = "SELECT rtrim(`编号`) as 编号, rtrim(`名称`) as 名称 FROM `物料_存货结构` WHERE `编号` IN ('0502','0503','0510','0511','0512','0513','0514','0520','0521','0523','0524','0525')";
  892. $data = Db::query($sql);
  893. $this->success('请求成功',$data);
  894. }
  895. /**
  896. *3.12印版资料-获取详细存货名称
  897. * @ApiMethod GET
  898. * @params string code
  899. */
  900. public function getProductYbMaterialDetail(){
  901. if (Request::instance()->isGet() == false){
  902. $this->error('非法请求');
  903. }
  904. $params = Request::instance()->get();
  905. if (empty($params) || !isset($params['code'])){
  906. $this->error('参数不能为空');
  907. }
  908. $code = $params['code'];
  909. $search = $params['search'];
  910. $num = config('product_code_digit');
  911. if (!empty($search)){
  912. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
  913. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  914. FROM `物料_存货编码` a
  915. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  916. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  917. WHERE a.物料代码 LIKE '{$code}%' AND a.物料名称 LIKE '%{$search}%'";
  918. }else{
  919. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
  920. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  921. FROM `物料_存货编码` a
  922. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  923. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  924. WHERE a.物料代码 LIKE '{$code}%'";
  925. }
  926. $data = Db::query($sql);
  927. $mergedArray = [];
  928. foreach ($data as $item) {
  929. $oneCode = '05';
  930. $twoCode = $item['twoCode'];
  931. $thrCode = $item['thrCode'];
  932. $oneName = '版材';
  933. $twoName = $item['twoName'];
  934. $thrName = $item['thrName'];
  935. $oneKey = "{$oneCode}/{$oneName}";
  936. $twoKey = "{$twoCode}/{$twoName}";
  937. $thrKey = "{$thrCode}/{$thrName}";
  938. if (!isset($mergedArray[$oneKey])) {
  939. $mergedArray[$oneKey] = [];
  940. }
  941. if (!isset($mergedArray[$oneKey][$twoKey])) {
  942. $mergedArray[$oneKey][$twoKey] = [];
  943. }
  944. $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
  945. }
  946. $this->success('请求成功',$mergedArray);
  947. }
  948. /**
  949. * 3.13印版资料-新增产品印版资料
  950. * @ApiMethod POST
  951. * @params array data
  952. */
  953. public function addProductYbInfo(){
  954. if (Request::instance()->isPost() == false){
  955. $this->error('非法请求');
  956. }
  957. $params = Request::instance()->post();
  958. $UniqId = \db('产品_印版资料')->order('UniqID desc')->value('UniqID');
  959. if ($UniqId < 2000000){
  960. $UniqId = 2000000;
  961. }else{
  962. $UniqId = $UniqId + 1;
  963. }
  964. $params['UniqID'] = $UniqId;
  965. $params['考核印数'] = '0.00';
  966. $params['Sys_rq'] = date('Y-m-d H:i:s');
  967. $sql = \db('产品_印版资料')->fetchSql(true)->insert($params);
  968. $res = Db::query($sql);
  969. if ($res !== false){
  970. $this->success('新增成功');
  971. }else{
  972. $this->error('新增失败');
  973. }
  974. }
  975. /**
  976. * 3.14工艺资料-获取损耗代号
  977. * @ApiMethod GET
  978. * @params code
  979. */
  980. public function getLossCode(){
  981. if (Request::instance()->isGet() == false){
  982. $this->error('非法请求');
  983. }
  984. $params = Request::instance()->get();
  985. if (empty($params) || !isset($params['code'])){
  986. $this->error('参数不能为空');
  987. }
  988. $code = $params['code'];
  989. $where['sys_bh|sys_mc'] = array('like','%'.$code.'%');
  990. $data = \db('dic_lzsh')
  991. ->where($where)
  992. ->field('rtrim(sys_bh) as sys_bh, rtrim(sys_mc) as sys_mc,sys_rate0,sys_rate1')
  993. ->select();
  994. $this->success('请求成功',$data);
  995. }
  996. /**
  997. * 产品工艺资料删除
  998. * @return void
  999. * @throws \think\Exception
  1000. * @throws \think\exception\PDOException
  1001. */
  1002. public function ProcessDetailDel()
  1003. {
  1004. if ($this->request->isGet() === false) {
  1005. $this->error('请求错误');
  1006. }
  1007. $param = $this->request->param();
  1008. if (isset($param['UniqId']) === false) {
  1009. $this->error('参数错误');
  1010. }
  1011. $printId = explode(',', $param['UniqId']);
  1012. $res = \db('产品_工艺资料')->where('UniqID','in',$printId)->delete();
  1013. if ($res){
  1014. $this->success('删除成功');
  1015. }else{
  1016. $this->error('删除失败');
  1017. }
  1018. }
  1019. /**
  1020. * 产品印件资料删除
  1021. * @return void
  1022. * @throws \think\Exception
  1023. * @throws \think\exception\PDOException
  1024. */
  1025. public function PrintDetailDel()
  1026. {
  1027. if ($this->request->isGet() === false){
  1028. $this->error('请求错误');
  1029. }
  1030. $param = $this->request->param();
  1031. if (isset($param['UniqId']) === false){
  1032. $this->error('参数错误');
  1033. }
  1034. $printId = explode(',',$param['UniqId']);
  1035. $res = \db('产品_印件资料')->where('UniqID','in',$printId)->delete();
  1036. if ($res){
  1037. $this->success('删除成功');
  1038. }else{
  1039. $this->error('删除失败');
  1040. }
  1041. }
  1042. /**
  1043. * 新增产品
  1044. * @ApiMethod POST
  1045. *
  1046. */
  1047. public function addProduct(){
  1048. if (Request::instance()->isPost() == false){
  1049. $this->error('非法请求');
  1050. }
  1051. $params = Request::instance()->post();
  1052. if (empty($params)){
  1053. $this->error('参数不能为空');
  1054. }
  1055. $uniqId = \db('产品_基本资料')->order('UniqID desc')->value('UniqID');
  1056. if (empty($uniqId)){
  1057. $params['UniqID'] = 1;
  1058. }else{
  1059. $params['UniqID'] = $uniqId + 1;
  1060. }
  1061. $params['Sys_rq'] = date('Y-m-d H:i:s');
  1062. $sql = \db('产品_基本资料')->fetchSql(true)->insert($params);
  1063. $res = Db::query($sql);
  1064. if ($res !== false){
  1065. $this->success('新增成功');
  1066. }else{
  1067. $this->error('新增失败');
  1068. }
  1069. }
  1070. /**
  1071. * 产品资料删除
  1072. * @return void
  1073. * @throws \think\exception\PDOException
  1074. */
  1075. public function ProductDel()
  1076. {
  1077. if ($this->request->isGet() === false){
  1078. $this->error('请求错误');
  1079. }
  1080. $param = $this->request->param();
  1081. if (isset($param['UniqId']) === false){
  1082. $this->error('参数错误');
  1083. }
  1084. $WorkOrderId = explode(',',$param['UniqId']);
  1085. $i = 0;
  1086. foreach ($WorkOrderId as $key=>$value){
  1087. //获取产品编号
  1088. $product = \db('产品_基本资料')
  1089. ->where('UniqID',$value)
  1090. ->value('rtrim(产品编号)');
  1091. //删除工单资料、工艺资料、印件资料
  1092. \db()->startTrans();
  1093. try {
  1094. \db('产品_基本资料')->where('UniqID',$value)->delete();
  1095. if (!empty(\db('产品_工艺资料')->where('Gy0_cpdh',$product)->find())){
  1096. \db('产品_工艺资料')->where('Gy0_cpdh',$product)->delete();
  1097. }
  1098. if (!empty(\db('产品_印件资料')->where('yj_cpdh',$product)->find())){
  1099. \db('产品_印件资料')->where('yj_cpdh',$product)->delete();
  1100. }
  1101. \db()->commit();
  1102. }catch (\Exception $e){
  1103. \db()->rollback();
  1104. $i++;
  1105. }
  1106. }
  1107. if ($i === 0){
  1108. $this->success('删除成功');
  1109. }else{
  1110. $this->error('删除失败');
  1111. }
  1112. }
  1113. /**
  1114. * 修改产品工艺资料
  1115. * @ApiMethod POST
  1116. *
  1117. */
  1118. public function productEdit(){
  1119. if (Request::instance()->isPost() == false){
  1120. $this->error('非法请求');
  1121. }
  1122. $params = Request::instance()->post();
  1123. if (empty($params)){
  1124. $this->error('参数不能为空');
  1125. }
  1126. $UniqId = $params['UniqID'];
  1127. unset($params['UniqID']);
  1128. $params['Mod_rq'] = date('Y-m-d H:i:s');
  1129. $sql = \db('产品_工艺资料')->where('UniqID',$UniqId)->fetchSql(true)->update($params);
  1130. $res = Db::query($sql);
  1131. if ($res !== false){
  1132. $this->success('修改成功');
  1133. }else{
  1134. $this->error('修改失败');
  1135. }
  1136. }
  1137. /**
  1138. * 获取联数
  1139. * @return void
  1140. * @throws \think\db\exception\DataNotFoundException
  1141. * @throws \think\db\exception\ModelNotFoundException
  1142. * @throws \think\exception\DbException
  1143. */
  1144. public function getCouplet()
  1145. {
  1146. if ($this->request->isGet() === false){
  1147. $this->error('请求错误');
  1148. }
  1149. $param = $this->request->param();
  1150. if (empty($param['product']) || empty($param['yjno'])){
  1151. $this->error('参数错误');
  1152. }
  1153. $list = \db('产品_印件资料')
  1154. ->where('yj_cpdh',$param['product'])
  1155. ->where('yj_yjno',$param['yjno'])
  1156. ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
  1157. ->find();
  1158. $process = \db('产品_工艺资料')
  1159. ->where('Gy0_cpdh',$param['product'])
  1160. ->where('Gy0_yjno',$param['yjno'])
  1161. ->order('Gy0_gxh desc')
  1162. ->value('Gy0_gxh');
  1163. $list['工序号'] = $process + 1;
  1164. $this->success('成功',$list);
  1165. }
  1166. }