Product.php 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  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 EasyWeChat\Kernel\Support\rsa_public_encrypt;
  8. use function fast\e;
  9. /**
  10. * 产品管理接口
  11. */
  12. class Product extends Api
  13. {
  14. protected $noNeedLogin = ['*'];
  15. protected $noNeedRight = ['*'];
  16. /**
  17. * 首页
  18. *
  19. */
  20. public function index()
  21. {
  22. $this->success('请求成功');
  23. }
  24. /**
  25. * 获取产品资料
  26. *
  27. * @ApiMethod GET
  28. *@param string custom_code
  29. *@param string limit
  30. *@param string page
  31. */
  32. public function getProduct(){
  33. if (Request::instance()->isGet() == false){
  34. $this->error('非法请求');
  35. }
  36. $params = Request::instance()->param();
  37. $limit = $params['limit'];
  38. $yjno = 10;
  39. if (!isset($limit)){
  40. $limit = 15;
  41. }
  42. if (!isset($params['page'])){
  43. $pages = 0;
  44. }else{
  45. $pages = ((int)$params['page'] -1 ) * (int)$limit;
  46. }
  47. $total = 0;
  48. if (isset($params['custom_code']) && !empty($params['custom_code'])){
  49. $customCode = $params['custom_code'];
  50. $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
  51. rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
  52. FROM `产品_基本资料` WHERE `客户编号` = '{$customCode}' ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END,
  53. `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
  54. $total = db('产品_基本资料')->where('客户编号',$customCode)->count();
  55. }else{
  56. if (isset($params['search']) && !empty($params['search'])){
  57. $search = $params['search'];
  58. $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
  59. rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
  60. FROM `产品_基本资料` WHERE `产品名称` LIKE '%{$search}%' OR `产品编号` LIKE '%{$search}%' ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END,
  61. `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
  62. $total = db('产品_基本资料')->where('产品名称','like','%'.$search.'%')->count();
  63. }else{
  64. $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
  65. rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
  66. FROM `产品_基本资料` ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END,
  67. `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
  68. $total = db('产品_基本资料')->count();
  69. }
  70. }
  71. $list = Db::query($sql);
  72. foreach ($list as $key=>$value){
  73. $code = trim($value['产品编号']);
  74. $gd_sql = "SELECT `接单日期` FROM `工单_基本资料` WHERE `成品代号` = '{$code}' ORDER BY Uniqid DESC";
  75. $gdRes = Db::query($gd_sql);
  76. $list[$key]['receiveDate'] = '';
  77. if (!empty($gdRes)){
  78. $list[$key]['receiveDate'] = $gdRes[0]['接单日期'];
  79. }
  80. if (isset($params['sort'])){
  81. $gy_sql = "SELECT * FROM `产品_工艺资料` WHERE Gy0_cpdh = '{$code}' AND Gy0_yjno >= '{$yjno}'";
  82. $gyRes = Db::query($gy_sql);
  83. }else{
  84. $gy_sql = "SELECT * FROM `产品_工艺资料` WHERE Gy0_cpdh = '{$code}'";
  85. $gyRes = Db::query($gy_sql);
  86. }
  87. $list[$key]['gyData'] = '';
  88. if (empty($gyRes)){
  89. $list[$key]['gyData'] = '缺';
  90. }
  91. if (isset($params['sort'])){
  92. $yj_sql = "SELECT COUNT(*) as total FROM `产品_印件资料` WHERE `yj_cpdh` = '{$code}' AND yj_yjno >= '{$yjno}'";
  93. $yjRes = Db::query($yj_sql);
  94. }else{
  95. $yj_sql = "SELECT COUNT(*) as total FROM `产品_印件资料` WHERE `yj_cpdh` = '{$code}'";
  96. $yjRes = Db::query($yj_sql);
  97. }
  98. $list[$key]['yjData'] = '无';
  99. if ($yjRes[0]['total'] > 0){
  100. $list[$key]['yjData'] = $yjRes[0]['total'];
  101. }
  102. }
  103. $data['data'] = $list;
  104. $data['total'] = $total;
  105. $this->success('请求成功',$data);
  106. }
  107. /**
  108. * 获取产品基础数据
  109. *
  110. * @ApiMethod POST
  111. *@param string product_code
  112. */
  113. public function getProductData(){
  114. if (Request::instance()->isGet() == false){
  115. $this->error('非法请求');
  116. }
  117. $params = Request::instance()->param();
  118. $code = $params['product_code'];
  119. if (!isset($code)){
  120. $this->error('参数不能为空');
  121. }
  122. if (isset($params['sort'])){
  123. $PriWhere['yj_yjno'] = ['>=',10];
  124. $proWhere['Gy0_yjno'] = ['>=',10];
  125. }else{
  126. $PriWhere['yj_yjno'] = ['<',10];
  127. $proWhere['Gy0_yjno'] = ['<',10];
  128. }
  129. $num = config('product_code_digit');
  130. //工艺资料
  131. $option['a.Gy0_cpdh'] = $code;
  132. $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 备注,
  133. 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,
  134. a.Sys_rq,a.Mod_rq,b.sys_rate0 as 基础损耗,b.sys_rate1 as 损耗率,a.UniqID';
  135. $gyRes = db('产品_工艺资料')->alias('a')
  136. ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
  137. ->where($option)->where($proWhere)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
  138. //印件资料
  139. $where['yj_cpdh'] = $code;
  140. $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,
  141. 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';
  142. $yjRes = db('产品_印件资料')->where($where)->where($PriWhere)->field($field)->select();
  143. //印版资料
  144. $filter['a.YB_Cpdh'] = $code;
  145. $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';
  146. $ybRes = db('产品_印版资料')->alias('a')
  147. ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码', 'left')
  148. ->join('物料_存货结构 c',
  149. 'LEFT(a.存货编码, CASE WHEN a.存货编码 REGEXP \'[a-zA-Z]\' THEN 5 ELSE 4 END) = c.编号',
  150. 'left'
  151. )
  152. ->where($filter)
  153. ->field($yb_field)
  154. ->order('a.YB_Yjno,a.存货编码')
  155. ->select();
  156. //技术附件
  157. $jsRes = db('产品_技术附件')
  158. ->where('关联产品','like','%'.$code.'%')
  159. ->select();
  160. foreach ($jsRes as $key=>&$value){
  161. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  162. $value['附件内容'] = '';
  163. }
  164. }
  165. $list = [];
  166. $list['yjData'] = $yjRes;
  167. $list['gyData'] = $gyRes;
  168. $list['ybData'] = $ybRes;
  169. $list['jsData'] = $jsRes;
  170. $this->success('请求成功',$list);
  171. }
  172. /**
  173. * 4.获取单个工艺数据(排产参数调整)
  174. *
  175. * @ApiMethod GET
  176. *@param string product_code
  177. */
  178. public function getProductGy(){
  179. if (Request::instance()->isGet() == false){
  180. $this->error('非法请求');
  181. }
  182. $params = Request::instance()->param();
  183. $code = $params['product_code'];
  184. if (!isset($code)){
  185. $this->error('参数不能为空');
  186. }
  187. $option['a.Gy0_cpdh'] = $code;
  188. if (!empty($params['plan'])){
  189. $option['a.Gy0_方案'] = $params['plan'];
  190. }
  191. $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,
  192. 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_辅助工时,
  193. rtrim(a.工序备注) as remark,a.人工检_正品板 as artificial_zp,a.人工检_次品板 as artificial_cp,a.人工检_废检 as artificial_fj,a.机检_正品板 as machine_zp,a.机检_次品板 as machine_cp,
  194. a.机检_废检 as machine_fj,rtrim(b.客户名称) as custom_name,rtrim(b.产品名称) as product_name,a.UniqId';
  195. $gyRes = db('产品_工艺资料')->alias('a')
  196. ->join('产品_基本资料 b','a.Gy0_cpdh = b.产品编号','left')
  197. ->where($option)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
  198. $this->success('请求成功',$gyRes);
  199. }
  200. /**
  201. * 修改工艺参数
  202. *
  203. * @ApiMethod
  204. * @params array data
  205. */
  206. public function editGy(){
  207. if (Request::instance()->isPost() == false){
  208. $this->error('非法请求');
  209. }
  210. $params = Request::instance()->post();
  211. if (!isset($params) || !isset($params[0]['UniqID'])){
  212. $this->error('参数不能为空');
  213. }
  214. $i = 0;
  215. foreach ($params as $key=>$value){
  216. $data = [];
  217. if (!empty($value['A_power'])){
  218. $data['A类产能'] = $value['A_power'];
  219. }
  220. if (!empty($value['shdh'])){
  221. $data['Gy0_shdh'] = $value['shdh'];
  222. }
  223. if (!empty($value['machine'])){
  224. $data['Gy0_sbbh'] = $value['machine'];
  225. }
  226. if (!empty($value['time'])){
  227. $data['Gy0_辅助工时'] = $value['time'];
  228. }
  229. if (!empty($value['difficulty_coe'])){
  230. $data['工价系数'] = $value['difficulty_coe'];
  231. }
  232. if (!empty($value['loss_coe'])){
  233. $data['损耗系数'] = $value['loss_coe'];
  234. }
  235. if (!empty($value['ms_coe'])){
  236. $data['Gy0_Ms'] = $value['ms_coe'];
  237. }
  238. if (!empty($value['Gy0_site'])){
  239. $data['Gy0_site'] = $value['Gy0_site'];
  240. }
  241. $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
  242. $res = Db::query($sql);
  243. if ($res !== false){
  244. $i++;
  245. }
  246. }
  247. if ($i !== 0){
  248. $this->success('更新成功');
  249. }else{
  250. $this->error('更新失败');
  251. }
  252. }
  253. /**
  254. * 修改产品信息
  255. *
  256. * @ApiMethod POST
  257. *
  258. * @params object data
  259. */
  260. public function editProduct(){
  261. if (Request::instance()->isPost() == false){
  262. $this->error('非法请求');
  263. }
  264. $params = Request::instance()->post();
  265. if (empty($params)){
  266. $this->error('参数不能为空');
  267. }
  268. if (!isset($params['印品代号'])){
  269. $this->error('印品代号不能为空');
  270. }
  271. $code = $params['印品代号'];
  272. unset($params['印品代号']);
  273. $sql = db('产品_基本资料')->where('产品编号',$code)->fetchSql(true)->update($params);
  274. $res = Db::query($sql);
  275. if ($res !== false){
  276. $this->success('更新成功');
  277. }else{
  278. $this->error('更新失败');
  279. }
  280. }
  281. /**
  282. * 设置产品状态
  283. *
  284. * @ApiMethod POST
  285. * @params string status
  286. * @params string code
  287. */
  288. public function setProductStatus(){
  289. if (Request::instance()->isPost() == false){
  290. $this->error('非法请求');
  291. }
  292. $params = Request::instance()->post();
  293. if (empty($params['code']) || empty($params['status'])){
  294. $this->error('参数不能为空');
  295. }
  296. $code = $params['code'];
  297. $status = '';
  298. if ($params['status'] == 2){
  299. $status = '停产';
  300. }
  301. $sql = db('产品_基本资料')->where('产品编号',$code)->fetchSql(true)->setField('状态',$status);
  302. $res = Db::query($sql);
  303. if ($res !== false){
  304. $this->success('更新成功');
  305. }else{
  306. $this->error('更新失败');
  307. }
  308. }
  309. /**
  310. * 获取产品工艺数量
  311. *
  312. * @ApiMethod GET
  313. * @params string code
  314. */
  315. public function getGyTotal(){
  316. if (Request::instance()->isGet() == false){
  317. $this->error('非法请求');
  318. }
  319. $params = Request::instance()->param();
  320. $code = $params['code'];
  321. if (!isset($code)){
  322. $this->error('参数不能为空');
  323. }
  324. $res = db('产品_工艺资料')->where('Gy0_cpdh',$code)->distinct(true)->column('rtrim(Gy0_方案) as gy_plan');
  325. $data['gy'] = $res;
  326. $product = db('产品_基本资料')->where('产品编号',$code)->find();
  327. $data['name'] = rtrim($product['产品名称']);
  328. $this->success('请求成功',$data);
  329. }
  330. /**
  331. * 复制产品工艺信息
  332. *
  333. * @ApiMethod POST
  334. * @params string from_code
  335. * @params string from_pro
  336. * @params string to_code
  337. * @params string to_pro
  338. * @params int is_copy_gy
  339. */
  340. public function copyProductGy()
  341. {
  342. $request = Request::instance();
  343. if (!$request->isPost()) {
  344. $this->error('非法请求');
  345. }
  346. $params = $request->post();
  347. if (empty($params['from_code']) || empty($params['to_code'])) {
  348. $this->error('参数不能为空');
  349. }
  350. $where = [];
  351. if (isset($params['type']) && $params['type'] == 1) {
  352. $where = ['Gy0_gxh' => ['>',20]];
  353. }
  354. // 定义数据处理策略
  355. $strategies = [
  356. 'gy' => [
  357. 'flag' => 'is_copy_gy',
  358. 'table' => '产品_工艺资料',
  359. 'source_field' => 'Gy0_cpdh',
  360. 'uniq_field' => 'UniqID',
  361. 'extra_check' => function () use ($params) {
  362. if (empty($params['to_pro'])) {
  363. $this->error('工艺方案不能为空');
  364. }
  365. },
  366. 'data_mapper' => function ($item, $seq) use ($params) {
  367. return [
  368. 'Gy0_方案' => $params['to_pro'],
  369. 'Gy0_cpdh' => $params['to_code'],
  370. 'UniqID' => $seq
  371. ];
  372. }
  373. ],
  374. 'yj' => [
  375. 'flag' => 'is_copy_yj',
  376. 'table' => '产品_印件资料',
  377. 'source_field' => 'yj_cpdh',
  378. 'uniq_field' => 'UniqId',
  379. 'data_mapper' => function ($item, $seq) use ($params) {
  380. return [
  381. 'yj_cpdh' => $params['to_code'],
  382. 'UniqId' => $seq
  383. ];
  384. }
  385. ],
  386. 'yb' => [
  387. 'flag' => 'is_copy_yb',
  388. 'table' => '产品_印版资料',
  389. 'source_field' => 'YB_Cpdh',
  390. 'uniq_field' => 'UniqID',
  391. 'data_mapper' => function ($item, $seq) use ($params) {
  392. return [
  393. 'YB_Cpdh' => $params['to_code'],
  394. 'UniqID' => $seq
  395. ];
  396. }
  397. ]
  398. ];
  399. $processed = false;
  400. foreach ($strategies as $key => $strategy) {
  401. if (($params[$strategy['flag']] ?? 0) != 1) continue;
  402. $processed = true;
  403. if (isset($strategy['extra_check'])) {
  404. call_user_func($strategy['extra_check']);
  405. }
  406. // 构建查询条件
  407. $query = db($strategy['table'])->where($strategy['source_field'], $params['from_code']);
  408. if ($key === 'gy') {
  409. $query->where($where)->where('Gy0_方案', $params['from_pro']);
  410. }
  411. $data = $query->select();
  412. if (empty($data)) {
  413. $this->error("参考产品无{$strategy['table']}数据");
  414. }
  415. // 生成序列号
  416. $maxId = db($strategy['table'])
  417. ->order("{$strategy['uniq_field']} desc")
  418. ->value($strategy['uniq_field']) ?: 0;
  419. // 处理数据
  420. $processedData = [];
  421. $currentSeq = 1;
  422. foreach ($data as $item) {
  423. unset($item[$strategy['uniq_field']]);
  424. $mapped = array_merge(
  425. $item,
  426. call_user_func($strategy['data_mapper'], $item, $maxId + $currentSeq)
  427. );
  428. $processedData[] = $mapped;
  429. $currentSeq++;
  430. }
  431. // 事务处理
  432. db()->startTrans();
  433. try {
  434. db($strategy['table'])
  435. ->where($strategy['source_field'], $params['to_code'])
  436. ->delete();
  437. if (!db($strategy['table'])->insertAll($processedData)) {
  438. throw new \Exception("Insert failed");
  439. }
  440. db()->commit();
  441. } catch (\Exception $e) {
  442. db()->rollback();
  443. $this->error("复制{$strategy['table']}数据失败: " . $e->getMessage());
  444. }
  445. }
  446. if (!$processed) {
  447. $this->error('请至少选择一个复制项目');
  448. }
  449. $this->success('数据复制成功');
  450. }
  451. /**
  452. * 工艺方案更名
  453. *
  454. * @ApiMethod POST
  455. * @params string code
  456. * @params string name
  457. */
  458. public function editGyName(){
  459. if (Request::instance()->isPost() == false){
  460. $this->error('非法请求');
  461. }
  462. $params = Request::instance()->post();
  463. if (empty($params['code']) || empty($params['old_name']) || empty($params['new_name'])){
  464. $this->error('参数不能为空');
  465. }
  466. $where['Gy0_cpdh'] = $params['code'];
  467. $where['Gy0_方案'] = $params['old_name'];
  468. $sql = db('产品_工艺资料')->where($where)->fetchSql(true)->setField('Gy0_方案',$params['new_name']);
  469. $res = Db::query($sql);
  470. if ($res !== false){
  471. $this->success('更新成功');
  472. }else{
  473. $this->error('更新失败');
  474. }
  475. }
  476. /**
  477. * 工艺方案附加
  478. *
  479. * @ApiMethod POST
  480. * @params object data
  481. */
  482. public function editGyNo(){
  483. if (Request::instance()->isPost() == false){
  484. $this->error('非法请求');
  485. }
  486. $params = Request::instance()->post();
  487. if (empty($params) || !isset($params[0]['UniqID'])){
  488. $this->error('参数不能为空');
  489. }
  490. $i = 0;
  491. foreach ($params as $key=>$value){
  492. $data = [];
  493. if (!empty($value['Gy0_yjno'])){
  494. $data['Gy0_yjno'] = $value['Gy0_yjno'];
  495. }
  496. if (!empty($value['Gy0_gxh'])){
  497. $data['Gy0_gxh'] = $value['Gy0_gxh'];
  498. }
  499. if (!empty($value['Gy0_Ks'])){
  500. $data['Gy0_Ks'] = $value['Gy0_Ks'];
  501. }
  502. if (!empty($value['Gy0_ls'])){
  503. $data['Gy0_ls'] = $value['Gy0_ls'];
  504. }
  505. $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
  506. $res = Db::query($sql);
  507. if ($res !== false){
  508. $i++;
  509. }
  510. }
  511. if ($i !== 0){
  512. $this->success('更新成功');
  513. }else{
  514. $this->error('更新失败');
  515. }
  516. }
  517. /**
  518. * 计损色数修正
  519. *
  520. * @ApiMethod POST
  521. * @params object data
  522. */
  523. public function editGyMs(){
  524. if (Request::instance()->isPost() == false){
  525. $this->error('非法请求');
  526. }
  527. $params = Request::instance()->post();
  528. if (empty($params) || !isset($params[0]['UniqID'])){
  529. $this->error('参数不能为空');
  530. }
  531. $i = 0;
  532. foreach ($params as $key=>$value){
  533. $data = [];
  534. if (!empty($value['Gy0_Ms'])){
  535. $data['Gy0_Ms'] = $value['Gy0_Ms'];
  536. }
  537. if (!empty($value['Gy0_Ks'])){
  538. $data['Gy0_Ks'] = $value['Gy0_Ks'];
  539. }
  540. if (!empty($value['Gy0_ls'])){
  541. $data['Gy0_ls'] = $value['Gy0_ls'];
  542. }
  543. $data['Add_gxmc'] = $value['Add_gxmc'];
  544. $data['工序备注'] = $value['remark'];
  545. $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
  546. $res = Db::query($sql);
  547. if ($res !== false){
  548. $i++;
  549. }
  550. }
  551. if ($i !== 0){
  552. $this->success('更新成功');
  553. }else{
  554. $this->error('更新失败');
  555. }
  556. }
  557. /**
  558. * 产品质检废品系数调整
  559. *
  560. * @ApiMethod POST
  561. * @params object data
  562. */
  563. public function editGyWaste(){
  564. if (Request::instance()->isPost() == false){
  565. $this->error('非法请求');
  566. }
  567. $params = Request::instance()->post();
  568. if (empty($params) || !isset($params[0]['UniqID'])){
  569. $this->error('参数不能为空');
  570. }
  571. $i = 0;
  572. foreach ($params as $key=>$value){
  573. $data = [];
  574. if (!empty($value['artificial_zp'])){
  575. $data['人工检_正品板'] = $value['artificial_zp'];
  576. }
  577. if (!empty($value['artificial_cp'])){
  578. $data['人工检_次品板'] = $value['artificial_cp'];
  579. }
  580. if (!empty($value['artificial_fj'])){
  581. $data['人工检_废检'] = $value['artificial_fj'];
  582. }
  583. if (!empty($value['machine_zp'])){
  584. $data['机检_正品板'] = $value['machine_zp'];
  585. }
  586. if (!empty($value['machine_cp'])){
  587. $data['机检_次品板'] = $value['machine_cp'];
  588. }
  589. if (!empty($value['machine_fj'])){
  590. $data['机检_废检'] = $value['machine_fj'];
  591. }
  592. $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
  593. $res = Db::query($sql);
  594. if ($res !== false){
  595. $i++;
  596. }
  597. }
  598. if ($i !== 0){
  599. $this->success('更新成功');
  600. }else{
  601. $this->error('更新失败');
  602. }
  603. }
  604. /**
  605. * 获取产品印件资料
  606. * @ApiMethod GET
  607. * @params string UniqId
  608. */
  609. public function getProductYjInfo(){
  610. if (Request::instance()->isGet() == false){
  611. $this->error('非法请求');
  612. }
  613. $params = Request::instance()->param();
  614. if (empty($params['UniqId']) || empty($params['UniqId'])){
  615. $this->error('参数错误');
  616. }
  617. $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,
  618. 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,
  619. 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";
  620. $list = \db('产品_印件资料')->where('UniqId',$params['UniqId'])->field($field)->select();
  621. $this->success('请求成功',$list);
  622. }
  623. /**
  624. * 修改产品印件资料
  625. * @ApiMethod POST
  626. * @params array data
  627. */
  628. public function editProductYjInfo(){
  629. if (Request::instance()->isPost() == false){
  630. $this->error('非法请求');
  631. }
  632. $params = Request::instance()->post();
  633. if (empty($params) || !isset($params['UniqId'])){
  634. $this->error('参数不能为空');
  635. }
  636. $UniqId = $params['UniqId'];
  637. unset($params['UniqId']);
  638. $res = \db('产品_印件资料')->where('UniqId',$UniqId)->update($params);
  639. if ($res !== false){
  640. $this->success('更新成功');
  641. }else{
  642. $this->error('更新失败');
  643. }
  644. }
  645. /**
  646. * 新增产品印件资料
  647. * @ApiMethod POST
  648. * @params array data
  649. */
  650. public function addProductYjInfo(){
  651. if (Request::instance()->isPost() == false){
  652. $this->error('非法请求');
  653. }
  654. $params = Request::instance()->post();
  655. $UniqId = \db('产品_印件资料')->order('UniqId desc')->value('UniqId');
  656. if ($UniqId < 2000000){
  657. $UniqId = 2000000;
  658. }else{
  659. $UniqId = $UniqId + 1;
  660. }
  661. $params['UniqId'] = $UniqId;
  662. $params['sys_rq'] = date('Y-m-d H:i:s');
  663. $res = \db('产品_印件资料')->insert($params);
  664. if ($res !== false){
  665. $this->success('新增成功');
  666. }else{
  667. $this->error('新增失败');
  668. }
  669. }
  670. /**
  671. * 获取印件代码及名称
  672. * @ApiMethod GET
  673. *
  674. */
  675. public function getProductYjList(){
  676. if (Request::instance()->isGet() == false){
  677. $this->error('非法请求');
  678. }
  679. $params = Request::instance()->get();
  680. $search = $params['search'];
  681. // $num = config('product_code_digit');
  682. $num = 5;
  683. if (!empty($search)){
  684. $sql = "SELECT DISTINCT
  685. rtrim(a.`物料代码`) AS `物料代码`,
  686. rtrim(a.`物料名称`) AS `物料名称`,
  687. rtrim(b.`客户编号`) AS `客户编号`,
  688. rtrim(b.`客户名称`) AS `客户名称`
  689. FROM
  690. `物料_存货编码` a
  691. JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,
  692. CASE
  693. WHEN a.`物料代码` REGEXP '[a-zA-Z]' THEN 5
  694. ELSE 4
  695. END
  696. ) = LEFT(b.`客户编号`,
  697. CASE
  698. WHEN a.`物料代码` REGEXP '[a-zA-Z]' THEN 5
  699. ELSE 4
  700. END
  701. )
  702. WHERE
  703. (a.`物料名称` LIKE '%{$search}%' OR a.`物料代码` LIKE '%{$search}%')
  704. GROUP BY
  705. a.`物料代码`
  706. ORDER BY
  707. a.`物料代码` ASC ";
  708. }else{
  709. $sql = "SELECT DISTINCT
  710. rtrim(a.`物料代码`) AS `物料代码`,
  711. rtrim(a.`物料名称`) AS `物料名称`,
  712. rtrim(b.`客户编号`) AS `客户编号`,
  713. rtrim(b.`客户名称`) AS `客户名称`
  714. FROM
  715. `物料_存货编码` a
  716. JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,
  717. CASE
  718. WHEN a.`物料代码` REGEXP '[a-zA-Z]' THEN 5
  719. ELSE 4
  720. END
  721. ) = LEFT(b.`客户编号`,
  722. CASE
  723. WHEN a.`物料代码` REGEXP '[a-zA-Z]' THEN 5
  724. ELSE 4
  725. END
  726. )
  727. ORDER BY
  728. a.`物料代码` ASC";
  729. }
  730. $data = Db::query($sql);
  731. // 初始化一个关联数组,用于存储相同客户编号的数据
  732. $groupedData = [];
  733. foreach ($data as $row) {
  734. $customerCode = substr($row['物料代码'],0,$num).substr($row['客户编号'],2,2).'/'.$row['客户名称'];
  735. $materialCodePrefix = substr($row['物料代码'], 0, $num);
  736. if ($materialCodePrefix == 'Y1401' ){
  737. $materialCodePrefix = $materialCodePrefix.'/糊盒类产品(含贴码)';
  738. }else{
  739. $materialCodePrefix = $materialCodePrefix.'/直接领用产品';
  740. }
  741. // 如果关联数组中不存在该物料代码前四位的键,则创建一个空数组
  742. if (!isset($groupedData[$materialCodePrefix])) {
  743. $groupedData[$materialCodePrefix] = [];
  744. }
  745. // 如果物料代码前四位数组中不存在该客户编号的键,则创建一个空数组
  746. if (!isset($groupedData[$materialCodePrefix][$customerCode])) {
  747. $groupedData[$materialCodePrefix][$customerCode] = [];
  748. }
  749. // 去除客户编号和客户名称
  750. unset($row['客户编号']);
  751. unset($row['客户名称']);
  752. // 将当前行的数据添加到相应的物料代码前四位和客户编号的数组中
  753. $groupedData[$materialCodePrefix][$customerCode][] = $row;
  754. }
  755. $this->success('请求成功',$groupedData);
  756. }
  757. /**
  758. * 获取纸张代号及名称
  759. * @ApiMethod GET
  760. * @params string search
  761. */
  762. public function getProductZzList(){
  763. if (Request::instance()->isGet() == false){
  764. $this->error('非法请求');
  765. }
  766. $params = Request::instance()->get();
  767. $search = $params['search'];
  768. $num = config('product_code_digit');
  769. if (!empty($search)){
  770. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
  771. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  772. FROM `物料_存货编码` a
  773. LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
  774. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  775. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  776. WHERE (a.物料名称 LIKE '%{$search}%' or a.物料代码 LIKE '%{$search}%') AND (
  777. a.物料代码 LIKE '00%'
  778. OR a.物料代码 LIKE '01%'
  779. OR a.物料代码 LIKE '04%'
  780. OR a.物料代码 LIKE '03%'
  781. OR a.物料代码 LIKE '14%'
  782. OR a.物料代码 LIKE 'Y00%'
  783. OR a.物料代码 LIKE 'Y01%'
  784. OR a.物料代码 LIKE 'Y04%'
  785. OR a.物料代码 LIKE 'J03%'
  786. OR a.物料代码 LIKE 'Y14%')";
  787. $data = Db::query($sql);
  788. }else{
  789. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
  790. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  791. FROM `物料_存货编码` a
  792. LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
  793. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  794. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  795. WHERE a.物料代码 LIKE 'Y00%' or a.物料代码 LIKE 'Y01%' or a.物料代码 LIKE 'Y04%' or a.物料代码 LIKE 'J03%' or a.物料代码 LIKE 'Y14%' OR
  796. a.物料代码 LIKE '00%' or a.物料代码 LIKE '01%' or a.物料代码 LIKE '04%' or a.物料代码 LIKE '03%' or a.物料代码 LIKE '14%'";
  797. $data = Db::query($sql);
  798. }
  799. $mergedArray = [];
  800. foreach ($data as $item) {
  801. $oneCode = $item['oneCode'];
  802. $twoCode = $item['twoCode'];
  803. $thrCode = $item['thrCode'];
  804. $oneName = $item['oneName'];
  805. $twoName = $item['twoName'];
  806. $thrName = $item['thrName'];
  807. // Create a unique key using the combination of oneCode, twoCode, and thrCode
  808. $oneKey = "{$oneCode}/{$oneName}";
  809. $twoKey = "{$twoCode}/{$twoName}";
  810. $thrKey = "{$thrCode}/{$thrName}";
  811. // Initialize arrays if not already set
  812. if (!isset($mergedArray[$oneKey])) {
  813. $mergedArray[$oneKey] = [];
  814. }
  815. if (!isset($mergedArray[$oneKey][$twoKey])) {
  816. $mergedArray[$oneKey][$twoKey] = [];
  817. }
  818. // Append items to the arrays
  819. $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
  820. }
  821. $this->success('请求成功',$mergedArray);
  822. }
  823. /**
  824. *3.6工艺资料-获取产品工艺资料
  825. */
  826. public function getProductGyInfo(){
  827. if (Request::instance()->isGet() == false){
  828. $this->error('非法请求');
  829. }
  830. $params = Request::instance()->param();
  831. if (empty($params['UniqID']) || empty($params['UniqID'])){
  832. $this->error('参数错误');
  833. }
  834. $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,
  835. 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 工序备注,
  836. rtrim(a.质量要求) as 质量要求,rtrim(a.质量隐患) as 质量隐患,a.UniqID";
  837. $data = \db('产品_工艺资料')->alias('a')
  838. ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
  839. ->where('a.UniqID',$params['UniqID'])
  840. ->field($field)
  841. ->find();
  842. $this->success('请求成功',$data);
  843. }
  844. /**
  845. * 3.7工艺资料-获取车间及工艺名称
  846. * @ApiMethod GET
  847. *
  848. */
  849. public function getDepartName(){
  850. if (Request::instance()->isGet() == false){
  851. $this->error('非法请求');
  852. }
  853. $param = $this->request->param();
  854. $data = \db('erp_常用字典')->where('分类','印刷工艺')->order('编号 asc')->column('名称');
  855. $resultArray = [];
  856. foreach ($data as $item) {
  857. $parts = explode('_', $item);
  858. // 使用第一个部分作为一级键,第二个部分作为二级键
  859. $firstKey = $parts[0];
  860. $secondKey = $parts[1];
  861. $thirdValue = $parts[2];
  862. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  863. }
  864. if (isset($param['sort'])){
  865. $result['标准工艺']['智能车间'] = $resultArray['标准工艺']['智能车间'];
  866. }else{
  867. unset($resultArray['标准工艺']['智能车间']);
  868. $result = $resultArray;
  869. }
  870. $this->success('请求成功',$result);
  871. }
  872. /**
  873. * 3.8工艺资料-新增产品工艺
  874. */
  875. public function addProductGyInfo(){
  876. if (Request::instance()->isPost() == false){
  877. $this->error('非法请求');
  878. }
  879. $params = Request::instance()->post();
  880. $UniqId = \db('产品_工艺资料')->order('UniqID desc')->value('UniqID');
  881. if ($UniqId < 2000000){
  882. $UniqId = 2000000;
  883. }else{
  884. $UniqId = $UniqId + 1;
  885. }
  886. $params['UniqID'] = $UniqId;
  887. $params['Sys_rq'] = date('Y-m-d H:i:s');
  888. $sql = \db('产品_工艺资料')->fetchSql(true)->insert($params);
  889. $res = Db::query($sql);
  890. if ($res !== false){
  891. $this->success('新增成功');
  892. }else{
  893. $this->error('新增失败');
  894. }
  895. }
  896. /**
  897. * 3.9印版资料-获取产品印版资料
  898. * @ApiMethod GET
  899. */
  900. public function getProductYbInfo(){
  901. if (Request::instance()->isGet() == false){
  902. $this->error('非法请求');
  903. }
  904. $params = Request::instance()->param();
  905. if (empty($params['UniqID']) || empty($params['UniqID'])){
  906. $this->error('参数错误');
  907. }
  908. $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,
  909. rtrim(b.Add_gxmc) as Add_gxmc,rtrim(c.物料名称) as 物料名称,rtrim(a.YB_cpdh) as YB_cpdh";
  910. $data = \db('产品_印版资料')->alias('a')
  911. ->join('产品_工艺资料 b','a.YB_cpdh = b.Gy0_cpdh and a.YB_Yjno = b.Gy0_yjno and a.YB_gxh = b.Gy0_gxh','left')
  912. ->join('物料_存货编码 c','a.存货编码 = c.物料代码','left')
  913. ->where('a.UniqID',$params['UniqID'])->field($field)->order('存货编码')->find();
  914. if (empty($data)){
  915. $this->error('未查询到产品印版资料');
  916. }
  917. $where['Gy0_site'] = [
  918. ['like','胶印%'],
  919. ['like','烫模%'],
  920. 'or'
  921. ];
  922. $option['Gy0_cpdh'] = $data['YB_cpdh'];
  923. $option['Gy0_gxh'] = ['<',10];
  924. $option['Gy0_sbbh'] = ['neq',''];
  925. $gyData = \db('产品_工艺资料')->where($option)->where($where)
  926. ->field('rtrim(Gy0_方案) as Gy0_方案,Gy0_yjno,Gy0_gxh,rtrim(gy0_gxmc) as gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')
  927. ->order('Gy0_yjno,Gy0_gxh')->select();
  928. $list = [];
  929. foreach ($gyData as $key=>$value){
  930. $yjno = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  931. $gxh = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  932. $list[$key]['gy'] = $value['Gy0_方案'].'-->'.$yjno.'-'.$gxh.' '.$value['gy0_gxmc'];
  933. $list[$key]['gxmc'] = $value['Add_gxmc'];
  934. }
  935. $data['gy_data'] = $list;
  936. $this->success('请求成功',$data);
  937. }
  938. /**
  939. * 3.10印版资料-修改产品印版资料
  940. * @ApiMethod POST
  941. * @params string UniqId
  942. */
  943. public function editProductYbInfo(){
  944. if (Request::instance()->isPost() == false){
  945. $this->error('非法请求');
  946. }
  947. $params = Request::instance()->post();
  948. if (empty($params) || !isset($params['UniqId'])){
  949. $this->error('参数不能为空');
  950. }
  951. $UniqId = $params['UniqId'];
  952. unset($params['UniqId']);
  953. $sql = \db('产品_印版资料')->where('UniqId',$UniqId)->fetchSql(true)->update($params);
  954. $res = Db::query($sql);
  955. if ($res !== false){
  956. $this->success('更新成功');
  957. }else{
  958. $this->error('更新失败');
  959. }
  960. }
  961. /**
  962. * 印版资料-获取物料名称
  963. * @ApiMethod GET
  964. *
  965. */
  966. public function getProductYbMaterialList(){
  967. if (Request::instance()->isGet() == false){
  968. $this->error('非法请求');
  969. }
  970. $sql = "SELECT rtrim(`编号`) as 编号, rtrim(`名称`) as 名称 FROM `物料_存货结构` WHERE `编号` IN ('0502','0503','0510','0511','0512','0513','0514','0520','0521','0523','0524','0525')";
  971. $data = Db::query($sql);
  972. $this->success('请求成功',$data);
  973. }
  974. /**
  975. *3.12印版资料-获取详细存货名称
  976. * @ApiMethod GET
  977. * @params string code
  978. */
  979. public function getProductYbMaterialDetail(){
  980. if (Request::instance()->isGet() == false){
  981. $this->error('非法请求');
  982. }
  983. $params = Request::instance()->get();
  984. if (empty($params) || !isset($params['code'])){
  985. $this->error('参数不能为空');
  986. }
  987. $code = $params['code'];
  988. $search = $params['search'];
  989. $num = config('product_code_digit');
  990. if (!empty($search)){
  991. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
  992. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  993. FROM `物料_存货编码` a
  994. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  995. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  996. WHERE a.物料代码 LIKE '{$code}%' AND a.物料名称 LIKE '%{$search}%'";
  997. }else{
  998. $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
  999. rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
  1000. FROM `物料_存货编码` a
  1001. LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
  1002. LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
  1003. WHERE a.物料代码 LIKE '{$code}%'";
  1004. }
  1005. $data = Db::query($sql);
  1006. $mergedArray = [];
  1007. foreach ($data as $item) {
  1008. $oneCode = '05';
  1009. $twoCode = $item['twoCode'];
  1010. $thrCode = $item['thrCode'];
  1011. $oneName = '版材';
  1012. $twoName = $item['twoName'];
  1013. $thrName = $item['thrName'];
  1014. $oneKey = "{$oneCode}/{$oneName}";
  1015. $twoKey = "{$twoCode}/{$twoName}";
  1016. $thrKey = "{$thrCode}/{$thrName}";
  1017. if (!isset($mergedArray[$oneKey])) {
  1018. $mergedArray[$oneKey] = [];
  1019. }
  1020. if (!isset($mergedArray[$oneKey][$twoKey])) {
  1021. $mergedArray[$oneKey][$twoKey] = [];
  1022. }
  1023. $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
  1024. }
  1025. $this->success('请求成功',$mergedArray);
  1026. }
  1027. /**
  1028. * 3.13印版资料-新增产品印版资料
  1029. * @ApiMethod POST
  1030. * @params array data
  1031. */
  1032. public function addProductYbInfo(){
  1033. if (Request::instance()->isPost() == false){
  1034. $this->error('非法请求');
  1035. }
  1036. $params = Request::instance()->post();
  1037. $UniqId = \db('产品_印版资料')->order('UniqID desc')->value('UniqID');
  1038. if ($UniqId < 2000000){
  1039. $UniqId = 2000000;
  1040. }else{
  1041. $UniqId = $UniqId + 1;
  1042. }
  1043. $params['UniqID'] = $UniqId;
  1044. $params['考核印数'] = '0.00';
  1045. $params['Sys_rq'] = date('Y-m-d H:i:s');
  1046. $sql = \db('产品_印版资料')->fetchSql(true)->insert($params);
  1047. $res = Db::query($sql);
  1048. if ($res !== false){
  1049. $this->success('新增成功');
  1050. }else{
  1051. $this->error('新增失败');
  1052. }
  1053. }
  1054. /**
  1055. * 3.14工艺资料-获取损耗代号
  1056. * @ApiMethod GET
  1057. * @params code
  1058. */
  1059. public function getLossCode(){
  1060. if (Request::instance()->isGet() == false){
  1061. $this->error('非法请求');
  1062. }
  1063. $params = Request::instance()->get();
  1064. if (empty($params) || !isset($params['code'])){
  1065. $this->error('参数不能为空');
  1066. }
  1067. $code = $params['code'];
  1068. $where['sys_bh|sys_mc'] = array('like','%'.$code.'%');
  1069. $data = \db('dic_lzsh')
  1070. ->where($where)
  1071. ->field('rtrim(sys_bh) as sys_bh, rtrim(sys_mc) as sys_mc,sys_rate0,sys_rate1')
  1072. ->select();
  1073. $this->success('请求成功',$data);
  1074. }
  1075. /**
  1076. * 产品工艺资料删除
  1077. * @return void
  1078. * @throws \think\Exception
  1079. * @throws \think\exception\PDOException
  1080. */
  1081. public function ProcessDetailDel()
  1082. {
  1083. if ($this->request->isGet() === false) {
  1084. $this->error('请求错误');
  1085. }
  1086. $param = $this->request->param();
  1087. if (isset($param['UniqId']) === false) {
  1088. $this->error('参数错误');
  1089. }
  1090. $printId = explode(',', $param['UniqId']);
  1091. $res = \db('产品_工艺资料')->where('UniqID','in',$printId)->delete();
  1092. if ($res){
  1093. $this->success('删除成功');
  1094. }else{
  1095. $this->error('删除失败');
  1096. }
  1097. }
  1098. /**
  1099. * 产品印件资料删除
  1100. * @return void
  1101. * @throws \think\Exception
  1102. * @throws \think\exception\PDOException
  1103. */
  1104. public function PrintDetailDel()
  1105. {
  1106. if ($this->request->isGet() === false){
  1107. $this->error('请求错误');
  1108. }
  1109. $param = $this->request->param();
  1110. if (isset($param['UniqId']) === false){
  1111. $this->error('参数错误');
  1112. }
  1113. $printId = explode(',',$param['UniqId']);
  1114. $res = \db('产品_印件资料')->where('UniqID','in',$printId)->delete();
  1115. if ($res){
  1116. $this->success('删除成功');
  1117. }else{
  1118. $this->error('删除失败');
  1119. }
  1120. }
  1121. /**
  1122. * 新增产品
  1123. * @ApiMethod POST
  1124. *
  1125. */
  1126. public function addProduct(){
  1127. if (Request::instance()->isPost() == false){
  1128. $this->error('非法请求');
  1129. }
  1130. $params = Request::instance()->post();
  1131. if (empty($params)){
  1132. $this->error('参数不能为空');
  1133. }
  1134. $uniqId = \db('产品_基本资料')->order('UniqID desc')->value('UniqID');
  1135. if (empty($uniqId)){
  1136. $params['UniqID'] = 1;
  1137. }else{
  1138. $params['UniqID'] = $uniqId + 1;
  1139. }
  1140. $params['Sys_rq'] = date('Y-m-d H:i:s');
  1141. $sql = \db('产品_基本资料')->fetchSql(true)->insert($params);
  1142. $res = Db::query($sql);
  1143. if ($res !== false){
  1144. $this->success('新增成功');
  1145. }else{
  1146. $this->error('新增失败');
  1147. }
  1148. }
  1149. /**
  1150. * 产品资料删除
  1151. * @return void
  1152. * @throws \think\exception\PDOException
  1153. */
  1154. public function ProductDel()
  1155. {
  1156. if ($this->request->isGet() === false){
  1157. $this->error('请求错误');
  1158. }
  1159. $param = $this->request->param();
  1160. if (isset($param['UniqId']) === false){
  1161. $this->error('参数错误');
  1162. }
  1163. $WorkOrderId = explode(',',$param['UniqId']);
  1164. $i = 0;
  1165. foreach ($WorkOrderId as $key=>$value){
  1166. //获取产品编号
  1167. $product = \db('产品_基本资料')
  1168. ->where('UniqID',$value)
  1169. ->value('rtrim(产品编号)');
  1170. //删除工单资料、工艺资料、印件资料
  1171. \db()->startTrans();
  1172. try {
  1173. \db('产品_基本资料')->where('UniqID',$value)->delete();
  1174. if (!empty(\db('产品_工艺资料')->where('Gy0_cpdh',$product)->find())){
  1175. \db('产品_工艺资料')->where('Gy0_cpdh',$product)->delete();
  1176. }
  1177. if (!empty(\db('产品_印件资料')->where('yj_cpdh',$product)->find())){
  1178. \db('产品_印件资料')->where('yj_cpdh',$product)->delete();
  1179. }
  1180. \db()->commit();
  1181. }catch (\Exception $e){
  1182. \db()->rollback();
  1183. $i++;
  1184. }
  1185. }
  1186. if ($i === 0){
  1187. $this->success('删除成功');
  1188. }else{
  1189. $this->error('删除失败');
  1190. }
  1191. }
  1192. /**
  1193. * 修改产品工艺资料
  1194. * @ApiMethod POST
  1195. *
  1196. */
  1197. public function productEdit(){
  1198. if (Request::instance()->isPost() == false){
  1199. $this->error('非法请求');
  1200. }
  1201. $params = Request::instance()->post();
  1202. if (empty($params)){
  1203. $this->error('参数不能为空');
  1204. }
  1205. $UniqId = $params['UniqID'];
  1206. unset($params['UniqID']);
  1207. $params['Mod_rq'] = date('Y-m-d H:i:s');
  1208. $sql = \db('产品_工艺资料')->where('UniqID',$UniqId)->fetchSql(true)->update($params);
  1209. $res = Db::query($sql);
  1210. if ($res !== false){
  1211. $this->success('修改成功');
  1212. }else{
  1213. $this->error('修改失败');
  1214. }
  1215. }
  1216. /**
  1217. * 获取联数
  1218. * @return void
  1219. * @throws \think\db\exception\DataNotFoundException
  1220. * @throws \think\db\exception\ModelNotFoundException
  1221. * @throws \think\exception\DbException
  1222. */
  1223. public function getCouplet()
  1224. {
  1225. if ($this->request->isGet() === false){
  1226. $this->error('请求错误');
  1227. }
  1228. $param = $this->request->param();
  1229. if (empty($param['product']) || empty($param['yjno'])){
  1230. $this->error('参数错误');
  1231. }
  1232. $list = \db('产品_印件资料')
  1233. ->where('yj_cpdh',$param['product'])
  1234. ->where('yj_yjno',$param['yjno'])
  1235. ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
  1236. ->find();
  1237. $process = \db('产品_工艺资料')
  1238. ->where('Gy0_cpdh',$param['product'])
  1239. ->where('Gy0_yjno',$param['yjno'])
  1240. ->order('Gy0_gxh desc')
  1241. ->value('Gy0_gxh');
  1242. $list['工序号'] = $process + 1;
  1243. $this->success('成功',$list);
  1244. }
  1245. /**
  1246. * 产品工艺排序
  1247. * @return void
  1248. * @throws \think\Exception
  1249. * @throws \think\exception\PDOException
  1250. */
  1251. public function ProductYgSort()
  1252. {
  1253. // 验证请求方法
  1254. if (!$this->request->isGet()) {
  1255. $this->error('请求错误');
  1256. }
  1257. // 获取并验证参数
  1258. $param = $this->request->param();
  1259. if (empty($param) || !isset($param['cpdh'])) {
  1260. $this->error('参数错误');
  1261. }
  1262. if (!isset($param['yjno']) && empty($param['yjno'])) {
  1263. $this->error('请选择印件');
  1264. }
  1265. // 构建查询条件
  1266. $where = ['Gy0_cpdh' => $param['cpdh']];
  1267. $where['Gy0_yjno'] = $param['yjno'];
  1268. // 获取待排序的数据
  1269. $list = \db('产品_工艺资料')
  1270. ->where($where)
  1271. ->order('Gy0_gxh,Sys_rq desc,Mod_rq desc')
  1272. ->column('Gy0_gxh', 'UniqID');
  1273. // 更新排序字段
  1274. $i = 1;
  1275. foreach ($list as $key => $value) {
  1276. if ((int)$value<20){
  1277. $result = \db('产品_工艺资料')
  1278. ->where('UniqID', $key)
  1279. ->update(['Gy0_gxh' => $i]);
  1280. if ($result !== false) {
  1281. $i++;
  1282. } else {
  1283. // 记录失败日志
  1284. \think\facade\Log::error("更新排序失败,UniqID: {$key}");
  1285. }
  1286. }
  1287. }
  1288. $this->success('成功');
  1289. }
  1290. }