Wigs.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Wigs extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_fullorder','fullorder');
  7. $this->load->_model('Model_fullordertt','fullordertt');
  8. $this->load->_model('Model_fullordersmt','fullordersmt');
  9. $this->load->_model('Model_shop','shop');
  10. $this->load->_model('Model_typeclass','typeclass');
  11. $this->load->_model('Model_express','express');
  12. $this->load->_model('Model_warehouse','warehouse');
  13. $this->load->_model('Model_customer','customer');
  14. $this->load->_model('Model_user','user');
  15. $this->load->_model('Model_headorder','headorder');
  16. $this->load->_model('Model_headorder_item','headorder_item');
  17. $this->load->_model('Model_whlabel','whlabel');
  18. $this->load->_model('Model_employee','employee');
  19. $this->load->library('order_process');
  20. $this->load->library('order_operation');
  21. }
  22. public function _remap($arg,$arg_array)
  23. {
  24. if($arg == 'add')//添加
  25. {
  26. $this->_add();
  27. }
  28. else if($arg == 'edit')//修改
  29. {
  30. $this->_edit($arg_array);
  31. }
  32. else if($arg == 'rows')//获取数据
  33. {
  34. $this->wigslist();
  35. }
  36. else if($arg == 'test')//获取数据
  37. {
  38. $this->test();
  39. }
  40. else if($arg == 'assign')//获取数据
  41. {
  42. $this->assign();
  43. }
  44. else if($arg == 'processAdd')//获取数据
  45. {
  46. $this->processAdd();
  47. }
  48. else if($arg == 'printall')//获取数据
  49. {
  50. $this->printAll();
  51. }
  52. else if($arg == 'print')//获取数据
  53. {
  54. $this->_print();
  55. }
  56. else if($arg == 'ok')//获取数据
  57. {
  58. $this->_ok();
  59. }
  60. else if($arg == 'print_ok')//获取数据
  61. {
  62. $this->print_ok();
  63. }else if($arg=="scan"){
  64. $this->scan();
  65. }
  66. else
  67. {
  68. $this->_index();
  69. }
  70. }
  71. public function _ok(){
  72. $this->_Template('wigslist_ok',$this->data);
  73. }
  74. public function _print()
  75. {
  76. $post = $this->input->post(NULL, TRUE);
  77. if(isset($_SESSION['api']))
  78. {
  79. $user = $this->user->get_api($_SESSION['api']);
  80. $usp = $user;
  81. $fgshop = "";$sid = "";$wid="";$wtype="";
  82. $usersp = explode('|',trim($user['shop'],'|'));
  83. $userwh = explode('|',trim($user['warehouse'],'|'));
  84. foreach ($usersp as $value)
  85. {
  86. $fgshop .= " shop = ".$value." or";
  87. $sid .= " id = ".$value." or";
  88. }
  89. foreach ($userwh as $value)
  90. {
  91. $wid .= " id = ".$value." or";
  92. $wtype .= " type = ".$value." or";
  93. }
  94. }
  95. if(isset($post['page']))
  96. {
  97. $page = $this->input->post('page',true);
  98. $perpage = $this->input->post('perpage',true);
  99. $timetk = $this->input->post('timetk',true);//订单开始时间
  100. $timetj = $this->input->post('timetj',true);//订单结束时间
  101. $shop = $this->input->post('shop',true);//店铺
  102. $wigs = $this->input->post('wigs',true);//订单状态 9.未打印 1.已打印 2.已分配 3. 已完成
  103. $orderinfo = $this->input->post('orderinfo',true);//订单号
  104. $print = $this->input->post('print',true);
  105. $number = $this->input->post('number',true);//订单编号
  106. $info = $this->input->post('info',true);
  107. $type = $this->input->post('type',true);//仓库
  108. $timetk = strtotime($timetk);
  109. $timetj = strtotime($timetj);
  110. $where = (isset($_SESSION['api']))?"mergeid != '1' and (state = '207' or state = '209') and (".rtrim($fgshop,'or').") and (".rtrim($wtype,'or').")":"id = '0'";
  111. if(empty($wigs)){
  112. $wigs=9;
  113. }
  114. // $wigs=9;
  115. if($wigs == '1')//已打印的订单
  116. {
  117. $where .= " and printtime > '$timetk' and printtime < '$timetj'";
  118. }
  119. else//未打印
  120. {
  121. $where .= " and express != 0 and printtype > 0 and printtype < 3 and print = 2 and review > 4 and library = 1";
  122. }
  123. if($shop)
  124. {
  125. $where .= " and shop = '$shop'";
  126. }
  127. if($wigs)
  128. {
  129. $where .= " and wigs>0 and wigs != 8 and wigs <= '$wigs'";
  130. }
  131. if($orderinfo)
  132. {
  133. $where .= " and orderinfo = '$orderinfo'";
  134. }
  135. if($number)
  136. {
  137. $where .= " and number = '$number'";
  138. }
  139. // if($type)
  140. // {
  141. // $where .= " and type = '$type'";
  142. // }
  143. //$where .=" and fpdata like '%Wigs%' ";
  144. $where .= " and type = 4";
  145. //数据排序
  146. // $order_str = ($print != 3)?"id desc":"printtime desc";
  147. $order_str = "id desc";
  148. if(empty($page))
  149. {
  150. $start = 0;
  151. $perpage = 1;
  152. }
  153. else
  154. {
  155. $start = ($page - 1)*$perpage;
  156. }
  157. $info_list = array();
  158. $info_listsmt = array();
  159. $dlz = 0; $smt = 0;
  160. if($info != 'fullordersmt')
  161. {
  162. //取得信息列表
  163. $info_list = $this->fullorder->find_all($where,'id,shop,orderinfo,number,shipremarks,wigs,wigsprinttime',$order_str,$start,$perpage);
  164. //格式化数据
  165. foreach ($info_list as $key=>$value)
  166. {
  167. $info_list[$key]['id'] = $value['id'].'-fullorder';
  168. $shop = $this->shop->read($value['shop']);
  169. $info_list[$key]['shop'] = $shop['shopname'];
  170. $info_list[$key]['wigsprinttime'] = ($value['wigsprinttime'] != '0')?date('Y-m-d H:i',$value['wigsprinttime']):'无';
  171. $info_list[$key]['orderinfo']='<div class="orderinfo">'.$info_list[$key]['orderinfo'].'</div>';
  172. if($value['wigs'] == 9)
  173. {
  174. $info_list[$key]['wigs'] = "未打印";
  175. }
  176. else if($value['wigs'] = 1)
  177. {
  178. $info_list[$key]['wigs'] = "已打印";
  179. }
  180. else if($value['wigs'] = 2)
  181. {
  182. $info_list[$key]['wigs'] = "已分配";
  183. }
  184. else if($value['wigs'] = 3)
  185. {
  186. $info_list[$key]['wigs'] = "已完成";
  187. }
  188. }
  189. $dlz = $this->fullorder->find_count($where);
  190. }
  191. if($info != 'fullorder')
  192. {
  193. $info_listsmt = $this->fullordersmt->find_all($where,'id,shop,orderinfo,number,shipremarks,wigs,wigsprinttime',$order_str,$start,$perpage);
  194. //格式化数据
  195. foreach ($info_listsmt as $key=>$value)
  196. {
  197. $info_listsmt[$key]['id'] = $value['id'].'-fullordersmt';
  198. $shop = $this->shop->read($value['shop']);
  199. $info_listsmt[$key]['shop'] = $shop['shopname'];
  200. $info_listsmt[$key]['wigsprinttime'] = ($value['wigsprinttime'] != '0')?date('Y-m-d H:i',$value['wigsprinttime']):'无';
  201. $info_listsmt[$key]['orderinfo']='<div class="orderinfo">'.$info_listsmt[$key]['orderinfo'].'</div>';
  202. if($value['wigs'] == '9')
  203. {
  204. $info_listsmt[$key]['wigs'] = "未打印";
  205. }
  206. else if($value['wigs'] = 1)
  207. {
  208. $info_listsmt[$key]['wigs'] = "已打印";
  209. }
  210. else if($value['wigs'] = 2)
  211. {
  212. $info_listsmt[$key]['wigs'] = "已分配";
  213. }
  214. else if($value['wigs'] = 3)
  215. {
  216. $info_listsmt[$key]['wigs'] = "已完成";
  217. }
  218. }
  219. $smt += $this->fullordersmt->find_count($where);
  220. }
  221. //$total += $this->fullorder_smt->find_count($where);
  222. $total = $dlz+$smt;
  223. $rows = array_merge($info_list,$info_listsmt);
  224. //$rows = array_slice($rows,$start,$perpage);
  225. $pagenum = ceil($total/$perpage);
  226. $over = $total-($start+$perpage);
  227. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($rows));//array_merge($info_list,$info_list_smt,$info_listsmt)
  228. echo json_encode($rows);exit;
  229. }
  230. if(isset($_SESSION['api']))
  231. {
  232. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  233. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'));
  234. $this->data['wlshop'] = $wlshop;
  235. $this->data['warehouse'] = $warehouse;
  236. }
  237. $this->_Template('wigsprint',$this->data);
  238. }
  239. public function processAdd(){
  240. $post = $this->input->post(NULL, TRUE);
  241. $ids = $this->input->post('ids',true);
  242. // if();
  243. $success=[];
  244. $fail=[];
  245. foreach($ids as $id){
  246. $process=$this->order_operation->handle('add',$id);
  247. if($process){
  248. $success[]=$id;
  249. }else{
  250. $fail[]=$id;
  251. }
  252. }
  253. //两种方案 1 只打印success 2 打印所有
  254. if(!empty($success)){
  255. $this->printAll($success);
  256. }
  257. echo json_encode(['status'=>0]);exit;
  258. // echo json_encode(['data'=>[
  259. // 'success'=>$success,
  260. // 'fail'=>$fail,
  261. // ]]);exit;
  262. }
  263. //头套带打印列表
  264. public function _index(){
  265. if(isset($_SESSION['api']))
  266. {
  267. $user = $this->user->get_api($_SESSION['api']);
  268. $usp = $user;
  269. $fgshop = "";$sid = "";
  270. $usersp = explode('|',trim($user['shop'],'|'));
  271. foreach ($usersp as $value)
  272. {
  273. $fgshop .= " shop = ".$value." or";
  274. $sid .= " id = ".$value." or";
  275. }
  276. if($user['vip'] == 1)
  277. {
  278. $vip = 1;
  279. }
  280. else
  281. {
  282. $vip = 0;
  283. }
  284. }
  285. else
  286. {
  287. $vip = 0;
  288. }
  289. $post = $this->input->post(NULL, TRUE);
  290. if(isset($post['page']))
  291. {
  292. $where='1=1';
  293. $page = $this->input->post('page',true);
  294. $perpage = $this->input->post('perpage',true);
  295. $status = $this->input->post('status',true);
  296. $orderinfo = $this->input->post('orderinfo',true);
  297. $number = $this->input->post('number',true);
  298. $timetk = $this->input->post('timetk',true);//订单开始时间
  299. $timetj = $this->input->post('timetj',true);//订单结束时间
  300. $timetk = strtotime($timetk);
  301. $timetj = strtotime($timetj);
  302. if(empty($page))
  303. {
  304. $start = 0;
  305. $perpage = 1;
  306. }
  307. else
  308. {
  309. $start = ($page - 1)*$perpage;
  310. }
  311. if($status){
  312. $where.=' and b.status="'.$status.'" ' ;
  313. }
  314. if($orderinfo){
  315. $where.=' and a.orderinfo like "%'.trim($orderinfo).'%" ' ;
  316. }
  317. if($number){
  318. $where.=' and a.orderinfo like "%'.trim($number).'%" ' ;
  319. }
  320. if(!empty($timetk))
  321. {
  322. $where .= " and a.created_at > '$timetk' and a.created_at < '$timetj'";
  323. }
  324. // $select=" a.id,a.number,a.shipma,a.warehouse,a.whlable,a.number,a.orderinfo,a.shipremarks,a.created_at,b.status_id,b.status,b.state,b.flow_id";
  325. $select="a.id,a.number,a.shipremarks,a.warehouse,a.orderinfo,b.status,a.orderremarks";
  326. $query=$this->db->select($select)
  327. ->from('headorder_item as a')
  328. ->join('process as b',' a.`id`=b.`order_id`','inner')
  329. // ->join('flow_status as c','b.`status_id`=c.id')
  330. ->where($where);
  331. $total=$query->count_all_results();
  332. $select='a.id,a.number,a.shipremarks,a.warehouse,a.orderinfo,b.status,a.orderremarks,e.name as username';
  333. $query=$this->db->select($select)
  334. ->from('headorder_item as a')
  335. ->join('process as b',' a.`id`=b.`order_id`','inner')
  336. ->join('employee as e', 'b.`uid`=e.id','left')
  337. ->order_by('a.id','DESC')
  338. // ->join('flow_status as c','b.`status_id`=c.id')
  339. ->where($where);
  340. $info_list=$query->limit($perpage,$start)->get()->result_array();
  341. foreach ($info_list as $k=>$v) {
  342. $warehouse = $this->warehouse->read($v['warehouse']);
  343. $warehousetitle = $warehouse['title'];
  344. if($v['warehouse'] != 1){$warehousetitle = "<font style='color:#f64b4b'>".$warehouse['title']."</font>";}
  345. $info_list[$k]['orderinfo']='<div class="orderinfo">'.$info_list[$k]['orderinfo'].'</div>';
  346. $info_list[$k]['warehouse'] = $warehousetitle;
  347. $info_list[$k]['status']=$this->headorder_item->getStatus($v['status']);
  348. if(empty($info_list[$k]['username'])){
  349. $info_list[$k]['username']='';
  350. }
  351. $info_list[$k]['action']='';
  352. // $info_list[$k]['action'].="<p class='ckn'><b class='fojzof' data-type='8' data-id='".$v['id']."'>打印</b></p>";
  353. $info_list[$k]['action'].="<p ><b class='assign' data-id='".$v['id']."'>分配订单</b></p>";
  354. }
  355. // $total = $this->headorder_item->find_count($where);
  356. $pagenum = ceil($total/$perpage);
  357. $over = $total-($start+$perpage);
  358. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  359. echo json_encode($rows);exit;
  360. }
  361. $this->_Template('wigslist',$this->data);
  362. }
  363. public function printAll($orderids=''){
  364. //获取所有状态<=1的订单 包含flow
  365. if(!isset($orderids)||empty($orderids)){
  366. $orderids = $this->input->post('orderids',true);
  367. }
  368. $orderinfo = $this->input->post('orderinfo',true);
  369. if(!$orderids and !$orderinfo){
  370. echo json_encode(['status'=>0,'msg'=>'缺少参数']);exit;
  371. }
  372. $where='c.flow_id=1 and b.state="'.Model_Process::STATUS_PROCESSING.'"';
  373. $select="a.id,a.number,a.shipremarks,a.warehouse,a.orderinfo,b.status,a.orderremarks";
  374. $query=$this->db->select($select)
  375. ->from('headorder_item as a')
  376. ->join('process as b',' a.`id`=b.`order_id`','inner')
  377. ->join('flow_status as c','b.`status_id`=c.id')
  378. ->where($where);
  379. if($orderids){
  380. $query->where_in('p_order',$orderids);
  381. }
  382. if($orderinfo){
  383. $query->where_in('orderinfo',$orderinfo);
  384. }
  385. $info_list=$query->get()->result_array();
  386. $data=[
  387. 'status'=>1,
  388. 'data'=>$info_list,
  389. ];
  390. echo json_encode($data);exit;
  391. }
  392. //
  393. public function print_ok(){
  394. $flow_id=1;
  395. $post = $this->input->post(NULL, TRUE);
  396. $orderIds=$post['ids'];
  397. // $orderIds=187;
  398. if(!$orderIds){
  399. echo json_encode(['status'=>'false'],true);exit;
  400. }
  401. $query= $this->db->select('*')
  402. ->from('process')
  403. ->where_in('order_id',$orderIds)
  404. // ->where('status','waitPrint')
  405. ->where('flow_id',$flow_id)
  406. ->where('state',Model_Process::STATUS_PROCESSING)
  407. ->get();
  408. $process_list=$query->result_array();
  409. foreach($process_list as $k=>$v){
  410. if($v['status']=="waitPrint"){
  411. $order=$this->headorder_item->read($v['order_id']);
  412. $order_process=new Model_Process();
  413. $order_process->read($v['id']);
  414. $order_process->toNextStatus($order);
  415. }
  416. }
  417. echo json_encode(['status'=>'ok'],true);exit;
  418. }
  419. public function scan(){
  420. $number = $this->input->post('number', TRUE);
  421. $flow_id=1;
  422. if(!$number){
  423. echo json_encode(['success'=>false,'msg'=>'缺少参数'],true);exit;
  424. }
  425. $headorder_item=$this->headorder_item->find('number="'.$number.'"');
  426. $info=$this->order_process->process($headorder_item['id']);
  427. if(empty($info)){
  428. echo json_encode(['success'=>false,'msg'=>'扫描数据有误'],true);exit;
  429. }
  430. if($info['status']=='waitScan'){
  431. if($info['state']!=Model_Process::STATUS_PROCESSING){
  432. echo json_encode(['success'=>false,'msg'=>'该订单已被取消,请确认订单状态'],true);exit;
  433. }
  434. $order=$this->headorder_item->read($info['order_id']);
  435. $order_process=new Model_Process();
  436. $order_process->read($info['id']);
  437. $order_process->toNextStatus($order);
  438. echo json_encode(['success'=>true,'msg'=>'扫描成功'],true);exit;
  439. }else{
  440. echo json_encode(['success'=>false,'msg'=>'已扫描'],true);exit;
  441. }
  442. }
  443. public function assign(){
  444. //TODO 判断权限
  445. $post = $this->input->post(NULL, TRUE);
  446. if(!isset($post['employee_id'])||empty($post['employee_id'])){
  447. $employee_list=$this->employee->find_all('sign_at >='.strtotime(date('Y-m-d 00:00:00')));
  448. if(empty($employee_list)){
  449. echo json_encode(array('msg'=>'未打卡,请打卡','success'=>false));exit;
  450. }
  451. echo json_encode(array('data'=>$employee_list,'success'=>true));exit;
  452. }else{
  453. $order_id=$post['order_id'];
  454. $employee_id=$post['employee_id'];
  455. if(!$order_id||!$employee_id){
  456. echo json_encode(['success'=>false,'msg'=>'缺少参数']);exit;
  457. }
  458. $info=$this->employee->read($employee_id);
  459. if(empty($info['sign_at'])||$info['sign_at']<strtotime(date('Y-m-d 00:00:00)'))){
  460. echo json_encode(['success'=>false,'msg'=>'未打卡']);exit;
  461. }
  462. //todo 判断订单状态
  463. $order=$this->headorder_item->read($order_id);
  464. $process=$this->order_process->process($order_id);
  465. if($process['state']!=Model_Process::STATUS_PROCESSING){
  466. echo json_encode(['success'=>false,'msg'=>'订单已经被取消,请确认订单状态']);exit;
  467. }
  468. $res=$this->db->set('uid',$employee_id)->where('order_id',$order_id)->update('process');
  469. if($process['status']!='waitAssign'){
  470. echo json_encode(['success'=>false,'msg'=>'状态异常']);exit;
  471. }
  472. $order_process=new Model_Process();
  473. $order_process->read($process['id']);
  474. if($res){
  475. $order_process->toNextStatus($order);
  476. echo json_encode(['success'=>true,'msg'=>'成功']);exit;
  477. }
  478. }
  479. }
  480. }