Purchasedetailed.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Purchasedetailed extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_purchasedetailed','purchasedetailed');
  7. $this->load->_model('Model_typeclass','typeclass');
  8. $this->load->_model('Model_pricedeploy','pricedeploy');
  9. $this->load->_model('Model_asd','asd');
  10. }
  11. //定义方法的调用规则 获取URI第二段值
  12. public function _remap($arg,$arg_array)
  13. {
  14. if($arg == 'add')//添加
  15. {
  16. $this->_add($arg_array);
  17. }
  18. else if($arg == 'edit')//修改
  19. {
  20. $this->_edit($arg_array);
  21. }
  22. else if($arg == 'del')//修改
  23. {
  24. $this->_del();
  25. }
  26. else if($arg == 'rows')//修改
  27. {
  28. $this->_rows();
  29. }
  30. else
  31. {
  32. $this->_index($arg_array);
  33. }
  34. }
  35. //管理
  36. public function _index($arg_array)
  37. {
  38. $post = $this->input->post(NULL, TRUE);
  39. if(isset($post['page']))
  40. {
  41. $page = $this->input->post('page',true);
  42. $perpage = $this->input->post('perpage',true);
  43. $category = $this->input->post('category',true);
  44. $size = $this->input->post('size',true);
  45. $grade = $this->input->post('grade',true);
  46. $density = $this->input->post('density',true);
  47. $lacetype = $this->input->post('lacetype',true);
  48. $arg_array = $this->input->post('arg_array',true);
  49. $where = "1=1 ";
  50. if($category)
  51. {
  52. $where .= " and category = '$category '";
  53. }
  54. if($size)
  55. {
  56. $where .= " and size = '$size'";
  57. }
  58. if($grade)
  59. {
  60. $where .= " and grade = '$grade'";
  61. }
  62. if($density)
  63. {
  64. $where .= " and density = '$density'";
  65. }
  66. if($lacetype)
  67. {
  68. $where .= " and lacetype = '$lacetype'";
  69. }
  70. if($arg_array || $arg_array != 0)
  71. {
  72. $where .= " and classid = '$arg_array'";
  73. }
  74. //数据排序
  75. $order_str = "id asc";
  76. if(empty($page))
  77. {
  78. $start = 0;
  79. $perpage = 1;
  80. }
  81. else
  82. {
  83. $start = ($page - 1)*$perpage;
  84. }
  85. //取得信息列表
  86. $info_list = $this->purchasedetailed->find_all($where,'id,category,size,grade,density,lacetype,lowe,color,haircap,money,classid',$order_str,$start,$perpage);
  87. foreach ($info_list as $key=>$value)
  88. {
  89. $category = $this->typeclass->read($value['category']);
  90. $info_list[$key]['category'] = $category['title'];
  91. $size = $this->typeclass->read($value['size']);
  92. $info_list[$key]['size'] = $size['title'];
  93. $grade = $this->typeclass->read($value['grade']);
  94. $info_list[$key]['grade'] = $grade['title'];
  95. if($value['density'] == 0)
  96. {
  97. $info_list[$key]['density'] = "未选择";
  98. }
  99. else
  100. {
  101. $density = $this->typeclass->read($value['density']);
  102. $info_list[$key]['density'] = $density['title'];
  103. }
  104. if($value['lacetype'] == 0)
  105. {
  106. $info_list[$key]['lacetype'] = "未选择";
  107. }
  108. else
  109. {
  110. $lacetype = $this->typeclass->read($value['lacetype']);
  111. $info_list[$key]['lacetype'] = $lacetype['title'];
  112. }
  113. $lowe = explode('|',trim($value['lowe'],'|'));
  114. $lowex = "";
  115. foreach ($lowe as $k=>$v)
  116. {
  117. $lower = $this->typeclass->read($v);
  118. $lowex = $lowex.$lower['title'].",";
  119. }
  120. $info_list[$key]['lowe'] = $lowex;
  121. $color = explode('|',trim($value['color'],'|'));
  122. $colorx = "";
  123. foreach ($color as $k=>$v)
  124. {
  125. $colorr = $this->typeclass->read($v);
  126. $colorx = $colorx.$colorr['title'].",";
  127. }
  128. $info_list[$key]['color'] = $colorx;
  129. if($value['haircap'])
  130. {
  131. $haircap = explode('|',trim($value['haircap'],'|'));
  132. $haircapx = "";
  133. foreach ($haircap as $k=>$v)
  134. {
  135. $haircapr = $this->typeclass->read($v);
  136. $haircapx = $haircapx.$haircapr['title'].",";
  137. }
  138. $info_list[$key]['haircap'] = $haircapx;
  139. }
  140. $money = $this->pricedeploy->read($value['classid']);
  141. if($money['money'] == 1)
  142. {
  143. $money = "CNY";
  144. }
  145. else
  146. {
  147. $money = "USD";
  148. }
  149. $info_list[$key]['money'] = $value['money']."(".$money.")";
  150. }
  151. $total = $this->purchasedetailed->find_count($where);
  152. $pagenum = ceil($total/$perpage);
  153. $over = $total-($start+$perpage);
  154. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  155. echo json_encode($rows);exit;
  156. }
  157. $category=array();$size=array();$grade=array();$density=array();$lacetype=array();$lowe=array();$color=array();$haircap=array();
  158. $typeclass = $this->typeclass->find_all();
  159. foreach ($typeclass as $key=>$value)
  160. {
  161. if($value['classid'] == 16)
  162. {
  163. $category[] = $value;
  164. }
  165. if($value['classid'] == 14)
  166. {
  167. $size[] = $value;
  168. }
  169. if($value['classid'] == 13)
  170. {
  171. $grade[] = $value;
  172. }
  173. if($value['classid'] == 10)
  174. {
  175. $density[] = $value;
  176. }
  177. if($value['classid'] == 19)
  178. {
  179. $lacetype[] = $value;
  180. }
  181. if($value['classid'] == 15)
  182. {
  183. $lowe[] = $value;
  184. }
  185. if($value['classid'] == 8)
  186. {
  187. $color[] = $value;
  188. }
  189. if($value['classid'] == 6)
  190. {
  191. $haircap[] = $value;
  192. }
  193. }
  194. $this->data['category'] = $category;
  195. $this->data['size'] = $size;
  196. $this->data['grade'] = $grade;
  197. $this->data['density'] = $density;
  198. $this->data['lacetype'] = $lacetype;
  199. $this->data['lowe'] = $lowe;
  200. $this->data['color'] = $color;
  201. $this->data['haircap'] = $haircap;
  202. if(isset($arg_array[0]))
  203. {
  204. $arg_array = $arg_array[0];
  205. }
  206. else
  207. {
  208. $arg_array = "";
  209. }
  210. $this->data['arg_array'] = $arg_array;
  211. $this->_Template('purchasedetailed',$this->data);
  212. }
  213. //添加
  214. public function _add($arg_array)
  215. {
  216. $post = $this->input->post(NULL, TRUE);
  217. if(isset($post['category']))
  218. {
  219. $post['classid'] = $this->input->post('class',true);
  220. $post['category'] = $this->input->post('category',true);
  221. $post['size'] = $this->input->post('size',true);
  222. $post['grade'] = $this->input->post('grade',true);
  223. $post['density'] = $this->input->post('density',true);
  224. $post['lacetype'] = $this->input->post('lacetype',true);
  225. $post['money'] = $this->input->post('money',true);
  226. $lowedata = $this->input->post('lowe',true);
  227. $colordata = $this->input->post('color',true);
  228. $haircapdata = $this->input->post('haircap',true);
  229. $post['lowe'] = "|".str_replace(',','|',$lowedata);
  230. $post['color'] = "|".str_replace(',','|',$colordata);
  231. $post['haircap'] = "|".str_replace(',','|',$haircapdata);
  232. if($this->purchasedetailed->insert($post))
  233. {
  234. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  235. }
  236. else
  237. {
  238. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  239. }
  240. }
  241. $category=array();$size=array();$grade=array();$density=array();$lacetype=array();$lowe=array();$color=array();$haircap=array();
  242. $typeclass = $this->typeclass->find_all();
  243. foreach ($typeclass as $key=>$value)
  244. {
  245. if($value['classid'] == 16)
  246. {
  247. $category[] = $value;
  248. }
  249. if($value['classid'] == 14)
  250. {
  251. $size[] = $value;
  252. }
  253. if($value['classid'] == 13)
  254. {
  255. $grade[] = $value;
  256. }
  257. if($value['classid'] == 10)
  258. {
  259. $density[] = $value;
  260. }
  261. if($value['classid'] == 19)
  262. {
  263. $lacetype[] = $value;
  264. }
  265. if($value['classid'] == 15)
  266. {
  267. $lowe[] = $value;
  268. }
  269. if($value['classid'] == 8)
  270. {
  271. $color[] = $value;
  272. }
  273. if($value['classid'] == 6)
  274. {
  275. $haircap[] = $value;
  276. }
  277. }
  278. $this->data['category'] = $category;
  279. $this->data['size'] = $size;
  280. $this->data['grade'] = $grade;
  281. $this->data['density'] = $density;
  282. $this->data['lacetype'] = $lacetype;
  283. $this->data['lowe'] = $lowe;
  284. $this->data['color'] = $color;
  285. $this->data['haircap'] = $haircap;
  286. $this->data['class'] = $arg_array[0];
  287. $this->_Template('purchasedetailed_add',$this->data);
  288. }
  289. //修改
  290. public function _edit($arg_array)
  291. {
  292. $post = $this->input->post(NULL, TRUE);
  293. if(isset($post['id']))
  294. {
  295. $id = $this->input->post('id',true);
  296. $post['category'] = $this->input->post('category',true);
  297. $post['size'] = $this->input->post('size',true);
  298. $post['grade'] = $this->input->post('grade',true);
  299. $post['density'] = $this->input->post('density',true);
  300. $post['lacetype'] = $this->input->post('lacetype',true);
  301. $post['money'] = $this->input->post('money',true);
  302. $lowedata = $this->input->post('lowe',true);
  303. $colordata = $this->input->post('color',true);
  304. $haircap = $this->input->post('haircap',true);
  305. $post['lowe'] = "|".str_replace(',','|',$lowedata);
  306. $post['color'] = "|".str_replace(',','|',$colordata);
  307. $post['haircap'] = "|".str_replace(',','|',$haircap);
  308. if($this->purchasedetailed->save($post,$id))
  309. {
  310. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  311. }
  312. else
  313. {
  314. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  315. }
  316. }
  317. $arg_array = $arg_array[0];
  318. $purchasedetailed = $this->purchasedetailed->read($arg_array);
  319. $this->data['purchasedetailed'] = $purchasedetailed;
  320. $this->data['xlowe'] = $purchasedetailed['lowe'];
  321. $this->data['xcolor'] = $purchasedetailed['color'];
  322. $this->data['xhaircap'] = $purchasedetailed['haircap'];
  323. $category=array();$size=array();$grade=array();$density=array();$lacetype=array();$lowe=array();$color=array();$haircap=array();
  324. $typeclass = $this->typeclass->find_all();
  325. foreach ($typeclass as $key=>$value)
  326. {
  327. if($value['classid'] == 16)
  328. {
  329. $category[] = $value;
  330. }
  331. if($value['classid'] == 14)
  332. {
  333. $size[] = $value;
  334. }
  335. if($value['classid'] == 13)
  336. {
  337. $grade[] = $value;
  338. }
  339. if($value['classid'] == 10)
  340. {
  341. $density[] = $value;
  342. }
  343. if($value['classid'] == 19)
  344. {
  345. $lacetype[] = $value;
  346. }
  347. if($value['classid'] == 15)
  348. {
  349. $lowe[] = $value;
  350. }
  351. if($value['classid'] == 8)
  352. {
  353. $color[] = $value;
  354. }
  355. if($value['classid'] == 6)
  356. {
  357. $haircap[] = $value;
  358. }
  359. }
  360. $this->data['category'] = $category;
  361. $this->data['size'] = $size;
  362. $this->data['grade'] = $grade;
  363. $this->data['density'] = $density;
  364. $this->data['lacetype'] = $lacetype;
  365. $this->data['lowe'] = $lowe;
  366. $this->data['color'] = $color;
  367. $this->data['haircap'] = $haircap;
  368. $this->_Template('purchasedetailed_edit',$this->data);
  369. }
  370. //删除
  371. public function _del()
  372. {
  373. $post = $this->input->post(NULL, TRUE);
  374. if(isset($post['s']))
  375. {
  376. $id_arr = $this->input->post('s');
  377. $id_arr = explode(',',$id_arr);
  378. if(!$id_arr)
  379. {
  380. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  381. }
  382. //循环删除记录
  383. foreach ($id_arr as $v)
  384. {
  385. $this->purchasedetailed->remove($v);
  386. }
  387. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  388. }
  389. }
  390. //rows
  391. public function _rows()
  392. {
  393. $info_list = $this->purchasedetailed->find_all();
  394. foreach ($info_list as $key=>$value)
  395. {
  396. }
  397. }
  398. }