Colour.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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 .= '<span class="deldata"><video src="'.$v.'" controls="controls"></video>'."<em style='width:30px;height:30px;line-height:30px;text-align: center;display: inline-block;position: absolute;top: 0px;right: 20px;z-index: 10;background-color: #FFF;cursor: pointer;' title='点击删除'>X</em></span>";
  206. }
  207. else if($v != '')
  208. {
  209. $url = 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);
  210. $url = explode('&',$url);
  211. $url = $url[0];
  212. $img .= '<span class="deldata"><a href="'.$url.'" target="_blank">'."<img src='".site_url('img/thumb')."?src=".$url."&w=500&h=500' data-src='".$v."'></a>"."<em style='width:30px;height:30px;line-height:30px;text-align: center;display: inline-block;position: absolute;top: 0px;right: 20px;z-index: 10;background-color: #FFF;cursor: pointer;' title='点击删除'>X</em></span>";
  213. }
  214. else
  215. {
  216. $img = '';
  217. }
  218. }
  219. $this->data['userid'] = $user['userid'];
  220. $colour['img'] = $img;
  221. $this->data['colour'] = $colour;
  222. $this->_Template('colour_edit',$this->data);
  223. }
  224. public function _see($arg_array)
  225. {
  226. $arg_array = $arg_array[0];
  227. $colour = $this->colour->read($arg_array);
  228. $colourimg = explode('|',$colour['img']);
  229. $img = array();$i = 1;
  230. foreach ($colourimg as $v)
  231. {
  232. $lx = explode(".",$v);
  233. $lx = strtolower(end($lx));
  234. /**
  235. if($lx == "3gp" || $lx == "rmvb" || $lx == "flv" || $lx == "wmv" || $lx == "avi" || $lx == "mkv" || $lx == "wav" || $lx == "mp4")
  236. {
  237. $img .= '<video src="'.$v.'" controls="controls"></video>';
  238. }
  239. else if($v != '')
  240. {
  241. $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>";
  242. }
  243. else
  244. {
  245. $img = '';
  246. }
  247. **/
  248. if($lx == "3gp" || $lx == "rmvb" || $lx == "flv" || $lx == "wmv" || $lx == "avi" || $lx == "mkv" || $lx == "wav" || $lx == "mp4")
  249. {
  250. $img[] = array('sp',$v);
  251. }
  252. else if($v != '')
  253. {
  254. $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>");
  255. }
  256. $i++;
  257. }
  258. $colour['img'] = $img;
  259. $this->data['colour'] = $colour;
  260. $this->_Template('colour_see',$this->data);
  261. }
  262. public function _seeindex()
  263. {
  264. if(isset($_SESSION['api']))
  265. {
  266. $user = $this->user->get_api($_SESSION['api']);
  267. $usp = $user;
  268. $fgshop = "";$sid = "";$wid="";$wtype="";
  269. $usersp = explode('|',trim($user['shop'],'|'));
  270. $userwh = explode('|',trim($user['warehouse'],'|'));
  271. foreach ($usersp as $value)
  272. {
  273. $fgshop .= " shop = ".$value." or";
  274. $sid .= " id = ".$value." or";
  275. }
  276. foreach ($userwh as $value)
  277. {
  278. $wid .= " id = ".$value." or";
  279. $wtype .= " warehouse = ".$value." or";
  280. }
  281. $fgshop .= " shop = '0' or";
  282. }
  283. $post = $this->input->post(NULL, TRUE);
  284. if(isset($post['page']))
  285. {
  286. $page = $this->input->post('page',true);
  287. $perpage = $this->input->post('perpage',true);
  288. $number = $this->input->post('number',true);
  289. $shop = $this->input->post('shop',true);
  290. $warehouse = $this->input->post('warehouse',true);
  291. $timetk = $this->input->post('timetk',true);
  292. $timetj = $this->input->post('timetj',true);
  293. $timetk = strtotime($timetk);
  294. $timetj = strtotime($timetj);
  295. $where = "(".rtrim($fgshop,'or').")";
  296. if($number)
  297. {
  298. $where .= " and number like '%$number%'";
  299. }
  300. if($shop)
  301. {
  302. $where .= " and shop = '$shop'";
  303. }
  304. if($warehouse)
  305. {
  306. $where .= " and warehouse = '$warehouse'";
  307. }
  308. if($timetk && $timetj)
  309. {
  310. $where .= " and time > '$timetk' and time < '$timetj'";
  311. }
  312. //数据排序
  313. $order_str = "id desc";
  314. if(empty($page))
  315. {
  316. $start = 0;
  317. $perpage = 1;
  318. }
  319. else
  320. {
  321. $start = ($page - 1)*$perpage;
  322. }
  323. $info_list = $this->colour->find_all($where,'id,number,shop,warehouse,time',$order_str,$start,$perpage);
  324. foreach ($info_list as $key=>$value)
  325. {
  326. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  327. if($value['shop'] == '0')
  328. {
  329. $info_list[$key]['shop'] = '常用色';
  330. }
  331. else
  332. {
  333. $shop = $this->shop->read($value['shop']);
  334. $info_list[$key]['shop'] = $shop['shopname'];
  335. }
  336. $warehouse = $this->warehouse->read($value['warehouse']);
  337. $info_list[$key]['warehouse'] = $warehouse['title'];
  338. }
  339. $total = $this->colour->find_count($where);
  340. $pagenum = ceil($total/$perpage);
  341. $over = $total-($start+$perpage);
  342. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  343. echo json_encode($rows);exit;
  344. }
  345. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  346. $this->data['wlshop'] = $wlshop;
  347. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  348. $this->data['warehouse'] = $warehouse;
  349. $this->_Template('colour_seeindex',$this->data);
  350. }
  351. public function _seephone()
  352. {
  353. $this->_Template('colour_seephone',$this->data);
  354. }
  355. //删除
  356. public function _del()
  357. {
  358. $post = $this->input->post(NULL, TRUE);
  359. if(isset($post['s']))
  360. {
  361. $id_arr = $this->input->post('s');
  362. $id_arr = explode(',',$id_arr);
  363. if(!$id_arr)
  364. {
  365. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  366. }
  367. //循环删除记录
  368. foreach ($id_arr as $v)
  369. {
  370. $this->colour->remove($v);
  371. }
  372. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  373. }
  374. }
  375. }