QcodeBach.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\QcodeCompany;
  4. use app\admin\model\QcodeProduct;
  5. use app\admin\model\QcodeGsmc;
  6. use app\admin\model\QcodeLarge;
  7. use app\admin\model\QcodeSmall;
  8. use app\common\controller\Backend;
  9. use \think\Session;
  10. use think\Db;
  11. /**
  12. *
  13. *
  14. * @icon fa fa-circle-o
  15. */
  16. class QcodeBach extends Backend
  17. {
  18. /**
  19. * Product模型对象
  20. * @var \app\admin\model\QcodeBach
  21. */
  22. protected $model = null;
  23. protected $multiFields = 'status';
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->model = new \app\admin\model\QcodeBach();
  28. }
  29. /**
  30. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  31. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  32. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  33. */
  34. /**
  35. * 查看
  36. */
  37. public function index()
  38. {
  39. //当前是否为关联查询
  40. $this->relationSearch = false;
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags', 'trim']);
  43. return $this->view->fetch();
  44. }
  45. /**
  46. * 查看
  47. */
  48. public function table1()
  49. {
  50. //当前是否为关联查询
  51. $this->relationSearch = false;
  52. //设置过滤方法
  53. $this->request->filter(['strip_tags', 'trim']);
  54. if ($this->request->isAjax()) {
  55. //如果发送的来源是Selectpage,则转发到Selectpage
  56. if ($this->request->request('keyField')) {
  57. return $this->selectpage();
  58. }
  59. $userInfo = Session::get('admin');
  60. $company_id = (int)$userInfo['company'];
  61. $where = [
  62. 'delete_time'=> ''
  63. ];
  64. $req = input();
  65. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  66. $order = $req['order'];
  67. $offset = $req['offset'];
  68. $limit = $req['limit'];
  69. // 构造模糊查询条件
  70. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  71. // $filter = ['field' => $regex];
  72. $filter = json_decode($req['filter'], true);
  73. foreach ($filter as $k => $v){
  74. $where[$k] = new \MongoDB\BSON\Regex($v);
  75. }
  76. $total = $this->model->name($company_id.'_'."qcode_bach")->where($where)->count();
  77. $list = $this->model->name($company_id.'_'."qcode_bach")->where($where)
  78. ->order($sort,$order)
  79. ->limit($limit)
  80. ->skip($offset)
  81. ->select();
  82. foreach ($list as $k=>$v) {
  83. $oid = $v['_id']->jsonSerialize();
  84. $list[$k]['id'] = $oid['$oid'];
  85. }
  86. $result = array("total" => $total, "rows" => $list);
  87. return json($result);
  88. }
  89. return $this->view->fetch();
  90. }
  91. /**
  92. * 查看
  93. */
  94. public function table2()
  95. {
  96. //当前是否为关联查询
  97. $this->relationSearch = false;
  98. //设置过滤方法
  99. $this->request->filter(['strip_tags', 'trim']);
  100. if ($this->request->isAjax()) {
  101. //如果发送的来源是Selectpage,则转发到Selectpage
  102. if ($this->request->request('keyField')) {
  103. return $this->selectpage();
  104. }
  105. $userInfo = Session::get('admin');
  106. $company_id = (int)$userInfo['company'];
  107. $where = [
  108. // 'company_id'=>(int)$userInfo['company'],
  109. 'delete_time'=> ''
  110. ];
  111. $req = input();
  112. if($req['filter']=='{}'){
  113. $result = array("total" => 0, "rows" => []);
  114. return json($result);
  115. }
  116. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  117. $order = $req['order'];
  118. $offset = $req['offset'];
  119. $limit = $req['limit'];
  120. // 构造模糊查询条件
  121. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  122. // $filter = ['field' => $regex];
  123. $filter = json_decode($req['filter'], true);
  124. foreach ($filter as $k => $v){
  125. $where[$k] = new \MongoDB\BSON\Regex($v);
  126. }
  127. $db = new QcodeLarge();
  128. $total = $db->name($company_id.'_'."qcode_large")->where($where)->count();
  129. $list = $db->name($company_id.'_'."qcode_large")->where($where)
  130. ->order($sort,$order)
  131. ->limit($limit)
  132. ->skip($offset)
  133. ->select();
  134. $qcodeSmall = new QcodeSmall();
  135. foreach ($list as $k=>$v) {
  136. $oid = $v['_id']->jsonSerialize();
  137. $list[$k]['id'] = $oid['$oid'];
  138. //设置当前托盘号
  139. $list[$k]['l_flow'] = ltrim(substr($v['code'],53,6),'0');
  140. //查询小件数量
  141. $small_num = $qcodeSmall->name($company_id.'_'."qcode_small")
  142. ->where('large_id',$oid['$oid'])
  143. ->count();
  144. $list[$k]['small_num'] = $small_num;
  145. //设置当前大件重量
  146. $list[$k]['l_weight'] = floatval($v['l_weight'])/100;
  147. }
  148. $result = array("total" => $total, "rows" => $list);
  149. return json($result);
  150. }
  151. return $this->view->fetch();
  152. }
  153. /**
  154. * 小件列表
  155. */
  156. public function small()
  157. {
  158. //设置过滤方法
  159. $this->request->filter(['strip_tags', 'trim']);
  160. $req = $this->request->param();
  161. if ($this->request->isAjax()) {
  162. //如果发送的来源是Selectpage,则转发到Selectpage
  163. if ($this->request->request('keyField')) {
  164. return $this->selectpage();
  165. }
  166. $userInfo = Session::get('admin');
  167. $company_id = (int)$userInfo['company'];
  168. $where = [
  169. 'delete_time'=> ''
  170. ];
  171. $req = input();
  172. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  173. $order = $req['order'];
  174. $offset = $req['offset'];
  175. $limit = $req['limit'];
  176. // 构造模糊查询条件
  177. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  178. // $filter = ['field' => $regex];
  179. $filter = json_decode($req['filter'], true);
  180. foreach ($filter as $k => $v){
  181. $where[$k] = new \MongoDB\BSON\Regex($v);
  182. }
  183. $qcodeSmall = new QcodeSmall();
  184. $total = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)->count();
  185. $list = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)
  186. ->order($sort,$order)
  187. ->limit($limit)
  188. ->skip($offset)
  189. ->select();
  190. foreach ($list as $k=>$v) {
  191. $oid = $v['_id']->jsonSerialize();
  192. $list[$k]['id'] = $oid['$oid'];
  193. $list[$k]['l_flow'] = $req['l_flow'].'-'.$v['l_flow'];
  194. }
  195. $result = array("total" => $total, "rows" => $list);
  196. return json($result);
  197. }
  198. return $this->view->fetch();
  199. }
  200. /**
  201. * 修改小件导出状态
  202. */
  203. public function small_status()
  204. {
  205. $req = $this->request->param();
  206. $ids = $req['ids'];
  207. $userInfo = Session::get('admin');
  208. $company_id = (int)$userInfo['company'];
  209. $qcodeSmall = new QcodeSmall();
  210. $status = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $ids)->value('status');
  211. if ($status === 0) {
  212. $newStatus = 1;
  213. } elseif ($status === 1) {
  214. $newStatus = 0;
  215. } else {
  216. // 处理其他情况,如果有需要
  217. }
  218. $bool = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $req['ids'])
  219. ->update(['status' => $newStatus]);
  220. if ($bool){
  221. $this->success("切换成功", null, ['id' => $ids]);
  222. }else{
  223. $this->error("切换失败", null, ['id' => $ids]);
  224. }
  225. }
  226. /**
  227. * 自动打码(大件)
  228. */
  229. public function print_l()
  230. {
  231. //设置过滤方法
  232. $this->request->filter(['strip_tags', 'trim']);
  233. $req = $this->request->param();
  234. if ($this->request->isAjax()) {
  235. parse_str($req['data'],$req);
  236. $ids = explode(',',$req['row']['ids']);
  237. $type = $req['row']['type'];
  238. $numn = $req['row']['numn'];
  239. $userInfo = Session::get('admin');
  240. $company_id = (int)$userInfo['company'];
  241. $qcodeLarge = new QcodeLarge();
  242. $qcodeSmall = new QcodeSmall();
  243. $qcodeProduct = new QcodeProduct();
  244. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
  245. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
  246. $row = $qcodeProduct->where('product_code',json_decode($bach,true)['matter_no'])->find();
  247. $company_name = json_decode($bach,true)['supplier_name'];
  248. $product_name = json_decode($bach,true)['matter_name'];
  249. // $date = json_decode($bach,true)['manufacture_date'];
  250. // $batch = json_decode($bach,true)['bach_num'];
  251. $main_unit = json_decode($row,true)['main_unit'];
  252. $sec_unit = json_decode($row,true)['sec_unit'];
  253. $proportion = json_decode($row,true)['proportion'];
  254. $rows = [];
  255. //查询打印大件码所需数据
  256. foreach ($ids as $key=>$value){
  257. $row = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
  258. $row = json_decode($row,true);
  259. $code = $row['code'];
  260. $rows[$key]['company_name'] = $company_name;
  261. $rows[$key]['product_name'] = $product_name;
  262. $rows[$key]['sqrcd'] = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->count();
  263. $rows[$key]['main_unit'] = $main_unit;
  264. $rows[$key]['sec_unit'] = $sec_unit;
  265. $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  266. $rows[$key]['l_flow'] = ltrim(substr($code,53,6),'0');
  267. $rows[$key]['qrcode'] = $code;
  268. $rows[$key]['pCode'] = $this->qrcode($code);
  269. //批次号特殊情况判断
  270. if (substr($code,76,10)=='0000000000'){
  271. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
  272. }else{
  273. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  274. }
  275. //转换关系判断
  276. if($row['l_num']===null){
  277. //走转换关系
  278. if ($proportion){
  279. $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
  280. $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
  281. }else{
  282. $rows[$key]['num'] = '';
  283. }
  284. }else if($row['l_num']==0){
  285. //判断是否是公斤
  286. if($main_unit=='公斤'){
  287. //公斤使用l_weight
  288. $rows[$key]['num'] = $row['l_weight'];
  289. }else{
  290. //不是公斤走转换关系
  291. if ($proportion){
  292. $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
  293. $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
  294. }else{
  295. $rows[$key]['num'] = '';
  296. }
  297. }
  298. }else{
  299. //箱, 使用l_num
  300. $rows[$key]['num'] = $row['l_num'];
  301. }
  302. }
  303. $data = [
  304. 'type'=>$type,
  305. 'numn'=>$numn,
  306. 'rows'=>$rows,
  307. 'ids'=>$ids,
  308. ];
  309. $this->success('成功','',$data);
  310. }
  311. $this->view->assign('ids',$req['ids']);
  312. return $this->view->fetch();
  313. }
  314. /**
  315. * 自动打码(小件)
  316. */
  317. public function print_s()
  318. {
  319. //设置过滤方法
  320. $this->request->filter(['strip_tags', 'trim']);
  321. $req = $this->request->param();
  322. if ($this->request->isAjax()) {
  323. parse_str($req['data'],$req);
  324. $ids = explode(',',$req['row']['ids']);
  325. $type = $req['row']['type'];
  326. $numn = $req['row']['numn'];
  327. $userInfo = Session::get('admin');
  328. $company_id = (int)$userInfo['company'];
  329. $qcodeLarge = new QcodeLarge();
  330. $qcodeSmall = new QcodeSmall();
  331. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
  332. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
  333. $company_name = json_decode($bach,true)['supplier_name'];
  334. $product_name = json_decode($bach,true)['matter_name'];
  335. //获取全部小件id
  336. $rows = [];
  337. $key = 0;
  338. foreach ($ids as $value){
  339. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
  340. $large = json_decode($large,true);
  341. $arr = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->column('_id');
  342. //查询打印大件码所需数据
  343. foreach ($arr as $v){
  344. $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$v->jsonSerialize()['$oid'])->find();
  345. $small = json_decode($small,true);
  346. $code = $small['code'];
  347. $rows[$key]['company_name'] = $company_name;
  348. $rows[$key]['product_name'] = $product_name;
  349. $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  350. $rows[$key]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
  351. $rows[$key]['qrcode'] = $code;
  352. // $rows[$key]['pCode'] = $this->qrcode($code);
  353. //批次号特殊情况判断
  354. if (substr($code,76,10)=='0000000000'){
  355. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
  356. }else{
  357. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  358. }
  359. $key++;
  360. }
  361. }
  362. $data = [
  363. 'type'=>$type,
  364. 'numn'=>$numn,
  365. 'rows'=>$rows,
  366. 'ids'=>$ids,
  367. ];
  368. $this->success('成功','',$data);
  369. }
  370. $this->view->assign('ids',$req['ids']);
  371. return $this->view->fetch();
  372. }
  373. /**
  374. * 手动打码(小件)
  375. */
  376. public function print_ls()
  377. {
  378. //设置过滤方法
  379. $this->request->filter(['strip_tags', 'trim']);
  380. $req = $this->request->param();
  381. if ($this->request->isAjax()) {
  382. parse_str($req['data'],$req);
  383. $ids = explode(',',$req['row']['ids']);
  384. $type = $req['row']['type'];
  385. $numn = $req['row']['numn'];
  386. $userInfo = Session::get('admin');
  387. $company_id = (int)$userInfo['company'];
  388. $qcodeLarge = new QcodeLarge();
  389. $qcodeSmall = new QcodeSmall();
  390. $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids[0])->find();
  391. $small = json_decode($small,true);
  392. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$small['large_id'])->find();
  393. $large = json_decode($large,true);
  394. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$small['bach_id'])->find();
  395. $company_name = json_decode($bach,true)['supplier_name'];
  396. $product_name = json_decode($bach,true)['matter_name'];
  397. //获取全部小件id
  398. $rows = [];
  399. $code = $small['code'];
  400. $rows[0]['company_name'] = $company_name;
  401. $rows[0]['product_name'] = $product_name;
  402. $rows[0]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  403. $rows[0]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
  404. $rows[0]['qrcode'] = $code;
  405. // $rows[0]['pCode'] = $this->qrcode($code);
  406. //批次号特殊情况判断
  407. if (substr($code,76,10)=='0000000000'){
  408. $rows[0]['batch'] = ltrim(substr($code,66,10),'0');
  409. }else{
  410. $rows[0]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  411. }
  412. $data = [
  413. 'type'=>$type,
  414. 'numn'=>$numn,
  415. 'rows'=>$rows,
  416. 'ids'=>$ids,
  417. ];
  418. $this->success('成功','',$data);
  419. }
  420. $this->view->assign('ids',$req['ids']);
  421. return $this->view->fetch();
  422. }
  423. /**
  424. * 设置打印数量
  425. */
  426. public function set_num()
  427. {
  428. $req = $this->request->param();
  429. //获取数据
  430. $status = $req['status'];
  431. $num = (int)$req['num'];
  432. $ids = $req['ids'];
  433. //获取company_id
  434. $userInfo = Session::get('admin');
  435. $company_id = (int)$userInfo['company'];
  436. //自动打印大件
  437. if($status==1){
  438. $qcodeLarge = new QcodeLarge();
  439. foreach ($ids as $v){
  440. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setInc('p_nums',$num);
  441. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setField('l_print','1');
  442. }
  443. }elseif($status==2){
  444. $qcodeSmall = new QcodeSmall();
  445. foreach ($ids as $v){
  446. $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$v)->setInc('p_nums',$num);
  447. }
  448. }elseif($status==3){
  449. $qcodeSmall = new QcodeSmall();
  450. $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids[0])->setInc('p_nums',$num);
  451. }
  452. }
  453. public function vo2()
  454. {
  455. $num1 = 0;
  456. $num2 = 1;
  457. if($num2<=$num1){
  458. $this->error('同步num1到num2之间的数据, 要求num2大于num1');
  459. }
  460. // 连接到其他数据库
  461. $config = [
  462. 'type' => 'mysql',
  463. 'hostname' => '127.0.0.1',
  464. 'database' => 'dm_7in6_com',
  465. 'username' => 'root',
  466. 'password' => 'root',
  467. 'charset' => 'utf8mb4',
  468. 'prefix' => 'qr_',
  469. ];
  470. $db = Db::connect($config);
  471. //查询主表记录
  472. $rows1 = $db->name('qcode_bach')
  473. ->limit($num1,$num2-$num1)
  474. ->order('id desc')
  475. ->select();
  476. $userInfo = Session::get('admin');
  477. $company_id = (int)$userInfo['company'];
  478. foreach($rows1 as $v){
  479. //1. 查询mongodb中是否存在该条记录
  480. $bool = $this->model->name($company_id.'_'."qcode_bach")->where('oid_id',$v['id'])->find();
  481. if ($bool) continue;
  482. //2. 获取设置主表数据
  483. $row = $v;
  484. unset($row['id']);
  485. $row = array_merge(['oid_id'=>$v['id']],$row);
  486. //3. 插入主表记录到mongodb中
  487. $qcodeBach = new \app\admin\model\QcodeBach();
  488. $qcodeBach->save($row);
  489. $pid = $qcodeBach->getLastInsID();
  490. $rows2 = $db->name('qcode_large')
  491. ->where('bach_id',$v['id'])
  492. ->select();
  493. foreach ($rows2 as $value){
  494. //1. 查询mongodb中是否存在该条记录
  495. $qcodeLarge = new QcodeLarge();
  496. $bool = $qcodeLarge->name($company_id.'_'."qcode_large")->where('oid_id',$value['id'])->find();
  497. if ($bool) continue;
  498. $row = $value;
  499. $row['old_bach_id'] = $value['bach_id'];
  500. $row['bach_id'] = $pid;
  501. $row['old_id'] = $value['id'];
  502. unset($row['id']);
  503. $qcodeLarge->save($row);
  504. $pid3 = $qcodeLarge->getLastInsID();
  505. $rows3 = $db->name('qcode_small')
  506. ->where('large_id',$value['id'])
  507. ->select();
  508. foreach ($rows3 as $value3){
  509. //1. 查询mongodb中是否存在该条记录
  510. $qcodeSmall = new QcodeSmall();
  511. $bool = $qcodeSmall->name($company_id.'_'."qcode_large")->where('oid_id',$value3['id'])->find();
  512. if ($bool) continue;
  513. $row = $value3;
  514. $row['old_bach_id'] = $value3['bach_id'];
  515. $row['old_large_id'] = $value3['large_id'];
  516. $row['old_id'] = $value3['id'];
  517. $row['bach_id'] = $pid;
  518. $row['large_id'] = $pid3;
  519. unset($row['id']);
  520. $qcodeSmall->save($row);
  521. }
  522. }
  523. }
  524. $this->success('成功');
  525. }
  526. /**
  527. * 跳转
  528. */
  529. public function exp()
  530. {
  531. //获取产品配置菜单id
  532. $bool = db('auth_rule')->field('id')->where('title','发货管理')->find();
  533. if ($bool){
  534. $this->success('成功','',$bool);
  535. }else{
  536. $this->error('未获取到菜单','',$bool);
  537. }
  538. }
  539. /**
  540. * 新增
  541. */
  542. public function add()
  543. {
  544. if ($this->request->isAjax()){
  545. $req = $this->request->post();
  546. if(!isset($req['row']['product_code']) || empty($req['row']['product_code'])){
  547. $this->error('请填写编号');
  548. }else{
  549. $data = [
  550. 'product_code'=>$req['row']['product_code'],
  551. 'delete_time'=>'',
  552. ];
  553. if ($this->model->where($data)->find()){
  554. $this->error('编号已存在');
  555. }
  556. }
  557. if(!isset($req['row']['product_name']) || empty($req['row']['product_name'])){
  558. $this->error('请填写名称');
  559. }else{
  560. $data = [
  561. 'product_name'=>$req['row']['product_name'],
  562. 'delete_time'=>'',
  563. ];
  564. if ($this->model->where($data)->find()){
  565. $this->error('名称已存在');
  566. }
  567. }
  568. if(!isset($req['row']['temple']) || empty($req['row']['temple'])){
  569. $this->error('请填写辅料代号');
  570. }
  571. if(!isset($req['row']['main_unit'])){
  572. $this->error('请填写主计量单位');
  573. }
  574. if(!isset($req['row']['sec_unit'])){
  575. $this->error('请填写辅计量单位');
  576. }
  577. if(!isset($req['row']['proportion'])){
  578. $this->error('请填写换算关系');
  579. }
  580. $data = [
  581. 'product_code' =>$req['row']['product_code'],
  582. 'product_name' =>$req['row']['product_name'],
  583. 'temple' =>$req['row']['temple'],
  584. 'main_unit' =>$req['row']['main_unit'],
  585. 'sec_unit' =>$req['row']['sec_unit'],
  586. 'proportion' =>$req['row']['proportion'],
  587. 'create_time' =>time(),
  588. ];
  589. //插入数据
  590. $re = $this->model->save($data);
  591. if($re){
  592. $this->success('成功');
  593. }else{
  594. $this->error('失败');
  595. }
  596. }
  597. return $this->view->fetch();
  598. }
  599. /**
  600. * 编辑
  601. */
  602. public function edit($ids = NULL)
  603. {
  604. $req = $this->request->param();
  605. if ($this->request->isAjax()){
  606. parse_str($req['data'],$req);
  607. if(!isset($req['row']['type']) || empty($req['row']['type'])){
  608. $this->error('请选择修改类型');
  609. }
  610. if(!isset($req['row']['numn']) || empty($req['row']['numn'])){
  611. $this->error('请填写修改数量');
  612. }
  613. $ids = explode(',',$req['row']['ids']);
  614. $data = [
  615. 'update_time'=>time(),
  616. 'sync_flag'=>0
  617. ];
  618. $userInfo = Session::get('admin');
  619. $company_id = (int)$userInfo['company'];
  620. $qcodeLarge = new QcodeLarge();
  621. if($req['row']['type']==1){//修改大件重量
  622. $data['l_weight'] = intval($req['row']['numn'])*100;
  623. foreach($ids as $val){
  624. //查询code
  625. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('code')->where('_id',$val)->find();
  626. $code = json_decode($large,true)['code'];
  627. if($code){
  628. $code1 = substr($code,0,59);
  629. $code2 = substr($code,65,85);
  630. $data['code'] = $code1.str_pad(intval($req['row']['numn'])*100,6, '0', STR_PAD_LEFT).$code2;
  631. //修改code和大件重量
  632. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data);
  633. }
  634. }
  635. $this->success('修改成功');
  636. }
  637. if($req['row']['type']==2){//修改大件总张数
  638. $data['l_num'] = intval($req['row']['numn']);
  639. foreach($ids as $val){
  640. //查询l_num, 判断是否可以修改总张数
  641. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('l_num')->where('_id',$val)->find();
  642. $l_num = json_decode($large,true)['l_num'];
  643. if($l_num > 0 || $l_num==null){
  644. //可以修改
  645. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data);
  646. }else{
  647. $this->error('该产品不能修改大件数量');
  648. }
  649. }
  650. $this->success('修改成功');
  651. }
  652. }
  653. $this->view->assign('ids',$req['ids']);
  654. return $this->view->fetch();
  655. }
  656. /**
  657. * 删除
  658. */
  659. public function del($ids = NULL)
  660. {
  661. $userInfo = Session::get('admin');
  662. $company_id = (int)$userInfo['company'];
  663. $qcodeLarge = new QcodeLarge();
  664. $qcodeSmall = new QcodeSmall();
  665. $data = [
  666. 'delete_time'=>time(),
  667. ];
  668. $bool1 = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$ids)->update($data);
  669. $bool2 = $qcodeLarge->name($company_id.'_'."qcode_large")->where('bach_id',$ids)->update($data);
  670. $bool3 = $qcodeSmall->name($company_id.'_'."qcode_small")->where('bach_id',$ids)->update($data);
  671. if($bool1!==false && $bool2!==false && $bool3!==false){
  672. $this->success('删除成功');
  673. }else{
  674. $this->error('删除失败');
  675. }
  676. }
  677. /**
  678. * 绑定
  679. */
  680. public function bind($ids = NULL)
  681. {
  682. $userInfo = Session::get('admin');
  683. $company_id = (int)$userInfo['company'];
  684. $db = new QcodeCompany();
  685. //查询是否已经添加
  686. $row = $db->name($company_id.'_'."qcode_company")
  687. ->where(['delete_time'=>'','product_id'=>$ids])
  688. ->find();
  689. if($row) $this->success('已添加');
  690. $data = [
  691. 'product_id'=>$ids,
  692. 'create_time'=>time(),
  693. ];
  694. //插入qcode_company数据
  695. $bool = $db->save($data);
  696. if($bool){
  697. $this->success('添加成功');
  698. }else{
  699. $this->error('添加失败');
  700. }
  701. }
  702. /**
  703. * 解绑
  704. */
  705. public function unbind($ids = NULL)
  706. {
  707. $userInfo = Session::get('admin');
  708. $company_id = (int)$userInfo['company'];
  709. $db = new QcodeCompany();
  710. //查询是否已经添加
  711. $bool = $db->name($company_id.'_'."qcode_company")
  712. ->where(['delete_time'=>'','product_id'=>$ids])
  713. ->update(['delete_time'=>date('Y-m-d H:i:s')]);
  714. if($bool){
  715. $this->success('删除成功');
  716. }else{
  717. $this->error('删除失败');
  718. }
  719. }
  720. /**
  721. * 补打标签
  722. */
  723. public function reprint()
  724. {
  725. if ($this->request->isAjax()) {
  726. $data = $this->request->param();
  727. parse_str($data['data'],$req);
  728. if(!isset($req['row']['nickname']) || empty($req['row']['nickname'])){
  729. $this->error('请填写公司名称');
  730. }
  731. if((!isset($req['row']['product_name']) || empty($req['row']['product_name'])) && (!isset($req['row']['product_code']) || empty($req['row']['product_code']))){
  732. $this->error('请填写辅料名称或辅料编号');
  733. }
  734. if(!isset($req['row']['sqrcd']) || empty($req['row']['sqrcd'])){
  735. $this->error('请填写配盘数');
  736. }
  737. if(!isset($req['row']['num']) || empty($req['row']['num'])){
  738. $this->error('请填写数量');
  739. }
  740. //查询公司信息
  741. $qcodeGsmc = new QcodeGsmc();
  742. $print_code = $qcodeGsmc
  743. ->field('id, nickname, print_code')
  744. ->where('nickname',$req['row']['nickname'])
  745. ->find();
  746. if (!$print_code) $this->error('未查到公司信息');
  747. $print_code = json_decode($print_code,true);
  748. //查询产品信息
  749. $qcodeProduct = new QcodeProduct();
  750. if(!empty($req['row']['product_code'])){
  751. $sel = $qcodeProduct
  752. ->field('id, product_name, product_code, temple')
  753. ->where('product_code',$req['row']['product_code'])
  754. ->find();
  755. }else{
  756. $sel = $qcodeProduct
  757. ->field('id, product_name, product_code, temple')
  758. ->where('product_name',$req['row']['product_name'])
  759. ->find();
  760. }
  761. if (!$sel) $this->error('未查到辅料信息');
  762. $sel = json_decode($sel,true);
  763. $data = [
  764. 'company_name'=>$req['row']['nickname'],
  765. 'product_name'=>$sel['product_name'],
  766. 'sqrcd'=>$req['row']['sqrcd'],
  767. 'num'=>$req['row']['num'],
  768. 'main_unit'=>'盘',
  769. 'sec_unit'=>'万米',
  770. 'date'=>date('Y-m-d'),
  771. 'batch'=>substr(date('Ymd'),2,6),
  772. 'l_flow'=>1,
  773. ];
  774. $num = str_pad($req['row']['num'], 3, '0', STR_PAD_LEFT);
  775. $qrcode = 'AB'.'92'.$sel['temple'].'0'.$print_code['print_code'].('000'.$sel['product_code']).$data['batch'].$num.$data['batch'].'000001'.'000000'.'2'.'0000'.$data['batch'].'0000000000';
  776. $data['pCode'] = $this->qrcode($qrcode);
  777. $data['qrcode'] = $qrcode;
  778. $this->success('成功','',$data);
  779. }
  780. return $this->view->fetch();
  781. }
  782. //公司搜索
  783. public function sel_n()
  784. {
  785. $name = $this->request->param()['q_word'][0];
  786. $where = [
  787. 'nickname'=>new \MongoDB\BSON\Regex($name),
  788. 'delete_time'=>'',
  789. ];
  790. $qcodeGsmc = new QcodeGsmc();
  791. $sel = $qcodeGsmc
  792. ->field('nickname')
  793. ->where($where)
  794. ->limit(0,10)
  795. ->select();
  796. return json(['list' => $sel, 'total' => count($sel)]);
  797. }
  798. //辅料名称搜索
  799. public function sel_p()
  800. {
  801. $name = $this->request->param()['q_word'][0];
  802. $where = [
  803. 'product_name'=>new \MongoDB\BSON\Regex($name),
  804. 'delete_time'=>'',
  805. ];
  806. $qcodeProduct = new QcodeProduct();
  807. $sel = $qcodeProduct
  808. ->field('product_name, product_code')
  809. ->where($where)
  810. ->limit(0,10)
  811. ->select();
  812. foreach ($sel as $k=>$v) {
  813. $oid = $v['_id']->jsonSerialize();
  814. $sel[$k]['id'] = $oid['$oid'];
  815. }
  816. return json(['list' => $sel, 'total' => count($sel)]);
  817. }
  818. //辅料编码搜索
  819. public function sel_c()
  820. {
  821. $name = $this->request->param()['q_word'][0];
  822. $where = [
  823. 'product_code'=>new \MongoDB\BSON\Regex($name),
  824. 'delete_time'=>'',
  825. ];
  826. $qcodeProduct = new QcodeProduct();
  827. $sel = $qcodeProduct
  828. ->field('id, product_name, product_code')
  829. ->where($where)
  830. ->limit(0,10)
  831. ->select();
  832. foreach ($sel as $k=>$v) {
  833. $oid = $v['_id']->jsonSerialize();
  834. $sel[$k]['id'] = $oid['$oid'];
  835. }
  836. return json(['list' => $sel, 'total' => count($sel)]);
  837. }
  838. /**
  839. * 二维码生成类
  840. */
  841. public function qrcode($url)//二维码生成类
  842. {
  843. $url=$url;
  844. $level=3;
  845. $size=6;
  846. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  847. $errorCorrectionLevel =intval($level) ;//容错级别
  848. $matrixPointSize = intval($size);//生成图片大小
  849. //生成二维码图片
  850. $object = new \QRcode();
  851. //打开缓冲区
  852. ob_start();
  853. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  854. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  855. $imageString = base64_encode(ob_get_contents());
  856. //关闭缓冲区
  857. ob_end_clean();
  858. //把生成的base64字符串返回给前端
  859. // $data = array(
  860. // 'labelcode'=>$url,
  861. // 'code'=>200,
  862. // 'data'=>$imageString,
  863. // 'product_code'=>$url
  864. // );
  865. return 'data:image/png;base64,'.$imageString;
  866. }
  867. }