Colour.php 13 KB

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