Productprice.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class productprice extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_productprice','productprice');
  7. $this->load->_model('Model_typeclass','typeclass');
  8. }
  9. //定义方法的调用规则 获取URI第二段值
  10. public function _remap($arg,$arg_array)
  11. {
  12. if($arg == 'add')//添加
  13. {
  14. $this->_add();
  15. }
  16. else if($arg == 'edit')//修改
  17. {
  18. $this->_edit($arg_array);
  19. }
  20. else if($arg == 'del')//修改
  21. {
  22. $this->_del();
  23. }
  24. else if($arg == 'rows')//获取数据
  25. {
  26. $this->_rows();
  27. }
  28. else
  29. {
  30. $this->_index();
  31. }
  32. }
  33. //管理
  34. public function _index()
  35. {
  36. $post = $this->input->post(NULL, TRUE);
  37. if(isset($post['page']))
  38. {
  39. $page = $this->input->post('page',true);
  40. $perpage = $this->input->post('perpage',true);
  41. $name = $this->input->post('name',true);
  42. $supplier = $this->input->post('supplier',true);
  43. $where = "1=1 ";
  44. if($name)
  45. {
  46. $where .= " and name = '$name'";
  47. }
  48. if($supplier)
  49. {
  50. $where .= " and supplier = '$supplier'";
  51. }
  52. //数据排序
  53. $order_str = "id asc";
  54. if(empty($page))
  55. {
  56. $start = 0;
  57. $perpage = 1;
  58. }
  59. else
  60. {
  61. $start = ($page - 1)*$perpage;
  62. }
  63. //取得信息列表
  64. $info_list = $this->productprice->find_all($where,'id,name,supplier,purchase,cost,salesprice,time,class',$order_str,$start,$perpage);
  65. foreach ($info_list as $key=>$value)
  66. {
  67. $purchase = $this->typeclass->read($value['purchase']);
  68. $info_list[$key]['purchase'] = $purchase['title'];
  69. $cost = $this->typeclass->read($value['cost']);
  70. $info_list[$key]['cost'] = $cost['title'];
  71. $salesprice = $this->typeclass->read($value['salesprice']);
  72. $info_list[$key]['salesprice'] = $salesprice['title'];
  73. $info_list[$key]['name'] = "<a href='/productdescribe/index/".$value['class']."'>".$value['name']."</a>";
  74. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  75. $info_list[$key]['class'] = '<span onclick=url("/productdescribe/index/'.$value['class'].'")>价格表明细配置</span><span onclick=copy("productprice","'.$value['class'].'")>复制价格表</span>';
  76. }
  77. $total = $this->productprice->find_count($where);
  78. $pagenum = ceil($total/$perpage);
  79. $over = $total-($start+$perpage);
  80. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  81. echo json_encode($rows);exit;
  82. }
  83. $this->_Template('productprice',$this->data);
  84. }
  85. //添加
  86. public function _add()
  87. {
  88. $post = $this->input->post(NULL, TRUE);
  89. if(isset($post['name']))
  90. {
  91. $post['name'] = $this->input->post('name',true);
  92. $post['supplier'] = $this->input->post('supplier',true);
  93. $post['user'] = $this->input->post('user',true);
  94. $post['phone'] = $this->input->post('phone',true);
  95. $post['purchase'] = $this->input->post('purchase',true);
  96. $post['cost'] = $this->input->post('cost',true);
  97. $post['salesprice'] = $this->input->post('salesprice',true);
  98. $time = $this->input->post('time',true);
  99. $post['time'] = strtotime($time);
  100. $post['operation'] = time().rand(1000,9999);
  101. if($this->productprice->insert($post))
  102. {
  103. $productprice = $this->productprice->get_operation($post['operation']);
  104. if($this->productprice->save(array('class'=>$productprice['id']),$productprice['id']))
  105. {
  106. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  107. }
  108. else
  109. {
  110. $this->productprice->remove($productprice['id']);
  111. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  112. }
  113. }
  114. else
  115. {
  116. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  117. }
  118. }
  119. $this->_Template('productprice_add',$this->data);
  120. }
  121. //修改
  122. public function _edit($arg_array)
  123. {
  124. $post = $this->input->post(NULL, TRUE);
  125. if(isset($post['id']))
  126. {
  127. $id = $this->input->post('id',true);
  128. $post['name'] = $this->input->post('name',true);
  129. $post['supplier'] = $this->input->post('supplier',true);
  130. $post['user'] = $this->input->post('user',true);
  131. $post['phone'] = $this->input->post('phone',true);
  132. $post['purchase'] = $this->input->post('purchase',true);
  133. $post['cost'] = $this->input->post('cost',true);
  134. $post['salesprice'] = $this->input->post('salesprice',true);
  135. $time = $this->input->post('time',true);
  136. $post['time'] = strtotime($time);
  137. if($this->productprice->save($post,$id))
  138. {
  139. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  140. }
  141. else
  142. {
  143. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  144. }
  145. }
  146. $arg_array = $arg_array[0];
  147. $productprice = $this->productprice->read($arg_array);
  148. $this->data['productprice'] = $productprice;
  149. $this->_Template('productprice_edit',$this->data);
  150. }
  151. //删除
  152. public function _del()
  153. {
  154. $post = $this->input->post(NULL, TRUE);
  155. if(isset($post['s']))
  156. {
  157. $id_arr = $this->input->post('s');
  158. $id_arr = explode(',',$id_arr);
  159. if(!$id_arr)
  160. {
  161. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  162. }
  163. //循环删除记录
  164. foreach ($id_arr as $v)
  165. {
  166. $this->productprice->remove($v);
  167. }
  168. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  169. }
  170. }
  171. //拷贝价格
  172. public function _rows()
  173. {
  174. $post = $this->input->post(NULL, TRUE);
  175. if(isset($post['copyid']))
  176. {
  177. $copyid = $this->input->post('copyid',true);
  178. $productprice = $this->productprice->read($copyid);
  179. $post['name'] = $productprice['name']."副本";
  180. $post['supplier'] = $productprice['supplier'];
  181. $post['user'] = $productprice['user'];
  182. $post['phone'] = $productprice['phone'];
  183. $post['purchase'] = $productprice['purchase'];
  184. $post['cost'] = $productprice['cost'];
  185. $post['salesprice'] = $productprice['salesprice'];
  186. $post['class'] = $productprice['class'];
  187. $post['time'] = $productprice['time'];
  188. if($this->productprice->insert($post))
  189. {
  190. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  191. }
  192. else
  193. {
  194. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  195. }
  196. }
  197. }
  198. }