Colour.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Colour extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_colour','colour');
  7. $this->load->_model('Model_shop','shop');
  8. $this->load->_model('Model_warehouse','warehouse');
  9. $this->load->_model('Model_fullorder','fullorder');
  10. $this->load->_model('Model_fullordertt','fullordertt');
  11. $this->load->_model('Model_fullordersmt','fullordersmt');
  12. }
  13. //定义方法的调用规则 获取URI第二段值
  14. public function _remap($arg,$arg_array)
  15. {
  16. if($arg == 'add')
  17. {
  18. $this->_add();
  19. }
  20. else if($arg == 'edit')
  21. {
  22. $this->_edit($arg_array);
  23. }
  24. else if($arg == 'see')
  25. {
  26. $this->_see($arg_array);
  27. }
  28. else if($arg == 'seeindex')
  29. {
  30. $this->_seeindex();
  31. }
  32. else if($arg == 'seephone')
  33. {
  34. $this->_seephone();
  35. }
  36. else if($arg == 'del')
  37. {
  38. $this->_del();
  39. }
  40. else
  41. {
  42. $this->_index();
  43. }
  44. }
  45. public function _index()
  46. {
  47. if(isset($_SESSION['api']))
  48. {
  49. $user = $this->user->get_api($_SESSION['api']);
  50. $usp = $user;
  51. $fgshop = "";$sid = "";
  52. $usersp = explode('|',trim($user['shop'],'|'));
  53. foreach ($usersp as $value)
  54. {
  55. $fgshop .= " shop = ".$value." or";
  56. $sid .= " id = ".$value." or";
  57. }
  58. $fgshop .= " shop = '0' or";
  59. }
  60. $post = $this->input->post(NULL, TRUE);
  61. if(isset($post['page']))
  62. {
  63. $page = $this->input->post('page',true);
  64. $perpage = $this->input->post('perpage',true);
  65. $number = $this->input->post('number',true);
  66. $shop = $this->input->post('shop',true);
  67. $warehouse = $this->input->post('warehouse',true);
  68. $timetk = $this->input->post('timetk',true);
  69. $timetj = $this->input->post('timetj',true);
  70. $timetk = strtotime($timetk);
  71. $timetj = strtotime($timetj);
  72. $where = "(".rtrim($fgshop,'or').")";
  73. if($number)
  74. {
  75. $where .= " and number like '%$number%'";
  76. }
  77. if($shop)
  78. {
  79. $where .= " and shop = '$shop'";
  80. }
  81. if($warehouse)
  82. {
  83. $where .= " and warehouse = '$warehouse'";
  84. }
  85. if($timetk && $timetj)
  86. {
  87. $where .= " and time > '$timetk' and time < '$timetj'";
  88. }
  89. //数据排序
  90. $order_str = "id desc";
  91. if(empty($page))
  92. {
  93. $start = 0;
  94. $perpage = 1;
  95. }
  96. else
  97. {
  98. $start = ($page - 1)*$perpage;
  99. }
  100. $info_list = $this->colour->find_all($where,'id,number,shop,warehouse,time',$order_str,$start,$perpage);
  101. foreach ($info_list as $key=>$value)
  102. {
  103. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  104. if($value['shop'] == '0')
  105. {
  106. $info_list[$key]['shop'] = '常用色';
  107. }
  108. else
  109. {
  110. $shop = $this->shop->read($value['shop']);
  111. $info_list[$key]['shop'] = $shop['shopname'];
  112. }
  113. $warehouse = $this->warehouse->read($value['warehouse']);
  114. $info_list[$key]['warehouse'] = $warehouse['title'];
  115. }
  116. $total = $this->colour->find_count($where);
  117. $pagenum = ceil($total/$perpage);
  118. $over = $total-($start+$perpage);
  119. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'cs'=>$fgshop);
  120. echo json_encode($rows);exit;
  121. }
  122. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  123. $this->data['wlshop'] = $wlshop;
  124. $this->_Template('colour',$this->data);
  125. }
  126. public function _add()
  127. {
  128. $post = $this->input->post(NULL, TRUE);
  129. if(isset($post['number']))
  130. {
  131. $number = $this->input->post('number',true);
  132. $post['number'] = trim($number,' ');
  133. $post['warehouse'] = $this->input->post('warehouse',true);
  134. $img = $this->input->post('img',true);
  135. $post['img'] = rtrim($img,'|');
  136. $post['content'] = $this->input->post('content',true);
  137. $post['time'] = time();
  138. if($this->colour->get_number($post['number']))
  139. {
  140. echo json_encode(array('msg'=>'此订单编号已存在!','success'=>false));exit;
  141. }
  142. if(stripos($post['number'],'#') !== false)
  143. {
  144. $post['shop'] = 0;
  145. }
  146. else
  147. {
  148. $number = $this->fullorder->get_number($post['number']);
  149. if(!$number)
  150. {
  151. $number = $this->fullordersmt->get_number($post['number']);
  152. if(!$number)
  153. {
  154. $number = $this->fullordertt->get_number($post['number']);
  155. if(!$number)
  156. {
  157. echo json_encode(array('msg'=>'订单中未找到此编号!','success'=>false));exit;
  158. }
  159. }
  160. }
  161. }
  162. $post['shop'] = $number['shop'];
  163. if($this->colour->insert($post))
  164. {
  165. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  166. }
  167. else
  168. {
  169. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  170. }
  171. }
  172. $this->_Template('colour_add',$this->data);
  173. }
  174. public function _edit($arg_array)
  175. {
  176. $user = $this->user->get_api($_SESSION['api']);
  177. $post = $this->input->post(NULL, TRUE);
  178. if(isset($post['id']))
  179. {
  180. $id = $this->input->post('id',true);
  181. $post['warehouse'] = $this->input->post('warehouse',true);
  182. $img = $this->input->post('img',true);
  183. $post['img'] = rtrim($img,'|');
  184. $post['content'] = $this->input->post('content',true);
  185. $post['edittime'] = time();
  186. if($this->colour->save($post,$id))
  187. {
  188. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  189. }
  190. else
  191. {
  192. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  193. }
  194. }
  195. $arg_array = $arg_array[0];
  196. $colour = $this->colour->read($arg_array);
  197. $colourimg = explode('|',$colour['img']);
  198. $img = '';
  199. foreach ($colourimg as $v)
  200. {
  201. $lx = explode(".",$v);
  202. $lx = strtolower(end($lx));
  203. if($lx == "3gp" || $lx == "rmvb" || $lx == "flv" || $lx == "wmv" || $lx == "avi" || $lx == "mkv" || $lx == "wav" || $lx == "mp4")
  204. {
  205. $img .= '<video src="'.$v.'" controls="controls" title="点击视频左上角删除"></video>';
  206. }
  207. else if($v != '')
  208. {
  209. $img .= "<img src='".site_url('img/thumb')."?src=".str_replace(array('http://'.$_SERVER['HTTP_HOST'],'http://erp.hnwmzp.cn','https://erp.hnwmzp.cn','http://1.wepolicy.cn/','https://1.wepolicy.cn/','/img/thumb?src='),'',$v)."&w=500&h=500' data-src='".$v."'>";
  210. }
  211. else
  212. {
  213. $img = '';
  214. }
  215. }
  216. $this->data['userid'] = $user['userid'];
  217. $colour['img'] = $img;
  218. $this->data['colour'] = $colour;
  219. $this->_Template('colour_edit',$this->data);
  220. }
  221. public function _see($arg_array)
  222. {
  223. $arg_array = $arg_array[0];
  224. $colour = $this->colour->read($arg_array);
  225. $colourimg = explode('|',$colour['img']);
  226. $img = array();$i = 1;
  227. foreach ($colourimg as $v)
  228. {
  229. $lx = explode(".",$v);
  230. $lx = strtolower(end($lx));
  231. /**
  232. if($lx == "3gp" || $lx == "rmvb" || $lx == "flv" || $lx == "wmv" || $lx == "avi" || $lx == "mkv" || $lx == "wav" || $lx == "mp4")
  233. {
  234. $img .= '<video src="'.$v.'" controls="controls"></video>';
  235. }
  236. else if($v != '')
  237. {
  238. $img .= "<a href='".$v."' download='".$colour['number']."第".$i."张图片'><img src='".site_url('img/thumb')."?src=".str_replace(array('http://'.$_SERVER['HTTP_HOST'],'http://erp.hnwmzp.cn','https://erp.hnwmzp.cn','http://1.wepolicy.cn/','img/thumb?src='),'',$v)."&w=500&h=500' data-src='".$v."'></a>";
  239. }
  240. else
  241. {
  242. $img = '';
  243. }
  244. **/
  245. if($lx == "3gp" || $lx == "rmvb" || $lx == "flv" || $lx == "wmv" || $lx == "avi" || $lx == "mkv" || $lx == "wav" || $lx == "mp4")
  246. {
  247. $img[] = array('sp',$v);
  248. }
  249. else if($v != '')
  250. {
  251. $img[] = array('tp',"<a href='".$v."' download='".$colour['number']."第".$i."张图片'><img src='".site_url('img/thumb')."?src=".str_replace(array('http://'.$_SERVER['HTTP_HOST'],'http://erp.hnwmzp.cn','https://erp.hnwmzp.cn','http://1.wepolicy.cn/','https://1.wepolicy.cn/','img/thumb?src='),'',$v)."&w=500&h=500' data-src='".$v."'></a>");
  252. }
  253. $i++;
  254. }
  255. $colour['img'] = $img;
  256. $this->data['colour'] = $colour;
  257. $this->_Template('colour_see',$this->data);
  258. }
  259. public function _seeindex()
  260. {
  261. if(isset($_SESSION['api']))
  262. {
  263. $user = $this->user->get_api($_SESSION['api']);
  264. $usp = $user;
  265. $fgshop = "";$sid = "";$wid="";$wtype="";
  266. $usersp = explode('|',trim($user['shop'],'|'));
  267. $userwh = explode('|',trim($user['warehouse'],'|'));
  268. foreach ($usersp as $value)
  269. {
  270. $fgshop .= " shop = ".$value." or";
  271. $sid .= " id = ".$value." or";
  272. }
  273. foreach ($userwh as $value)
  274. {
  275. $wid .= " id = ".$value." or";
  276. $wtype .= " warehouse = ".$value." or";
  277. }
  278. $fgshop .= " shop = '0' or";
  279. }
  280. $post = $this->input->post(NULL, TRUE);
  281. if(isset($post['page']))
  282. {
  283. $page = $this->input->post('page',true);
  284. $perpage = $this->input->post('perpage',true);
  285. $number = $this->input->post('number',true);
  286. $shop = $this->input->post('shop',true);
  287. $warehouse = $this->input->post('warehouse',true);
  288. $timetk = $this->input->post('timetk',true);
  289. $timetj = $this->input->post('timetj',true);
  290. $timetk = strtotime($timetk);
  291. $timetj = strtotime($timetj);
  292. $where = "(".rtrim($fgshop,'or').")";
  293. if($number)
  294. {
  295. $where .= " and number like '%$number%'";
  296. }
  297. if($shop)
  298. {
  299. $where .= " and shop = '$shop'";
  300. }
  301. if($warehouse)
  302. {
  303. $where .= " and warehouse = '$warehouse'";
  304. }
  305. if($timetk && $timetj)
  306. {
  307. $where .= " and time > '$timetk' and time < '$timetj'";
  308. }
  309. //数据排序
  310. $order_str = "id desc";
  311. if(empty($page))
  312. {
  313. $start = 0;
  314. $perpage = 1;
  315. }
  316. else
  317. {
  318. $start = ($page - 1)*$perpage;
  319. }
  320. $info_list = $this->colour->find_all($where,'id,number,shop,warehouse,time',$order_str,$start,$perpage);
  321. foreach ($info_list as $key=>$value)
  322. {
  323. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  324. if($value['shop'] == '0')
  325. {
  326. $info_list[$key]['shop'] = '常用色';
  327. }
  328. else
  329. {
  330. $shop = $this->shop->read($value['shop']);
  331. $info_list[$key]['shop'] = $shop['shopname'];
  332. }
  333. $warehouse = $this->warehouse->read($value['warehouse']);
  334. $info_list[$key]['warehouse'] = $warehouse['title'];
  335. }
  336. $total = $this->colour->find_count($where);
  337. $pagenum = ceil($total/$perpage);
  338. $over = $total-($start+$perpage);
  339. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  340. echo json_encode($rows);exit;
  341. }
  342. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  343. $this->data['wlshop'] = $wlshop;
  344. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  345. $this->data['warehouse'] = $warehouse;
  346. $this->_Template('colour_seeindex',$this->data);
  347. }
  348. public function _seephone()
  349. {
  350. $this->_Template('colour_seephone',$this->data);
  351. }
  352. //删除
  353. public function _del()
  354. {
  355. $post = $this->input->post(NULL, TRUE);
  356. if(isset($post['s']))
  357. {
  358. $id_arr = $this->input->post('s');
  359. $id_arr = explode(',',$id_arr);
  360. if(!$id_arr)
  361. {
  362. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  363. }
  364. //循环删除记录
  365. foreach ($id_arr as $v)
  366. {
  367. $this->colour->remove($v);
  368. }
  369. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  370. }
  371. }
  372. }