Product.php 42 KB

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