PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Application/Admin/Controller/ExchangeController.class.php

https://gitlab.com/xuebutayan/yshop
PHP | 274 lines | 215 code | 18 blank | 41 comment | 39 complexity | 3acda47f22e0ac8f1af019e1bf7f125c MD5 | raw file
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * 后台换货订单控制器
  5. *
  6. */
  7. class ExchangeController extends AdminController {
  8. /**
  9. * 换货管理
  10. */
  11. public function index(){
  12. $status=$_GET['status'];
  13. if(isset($_GET['status'])){
  14. switch ($status) {
  15. case '1':
  16. $map['status']=$status;
  17. $meta_title="提交换货商品";
  18. break;
  19. case '2':
  20. $map['status']=$status;
  21. $meta_title="同意换货商品";
  22. break;
  23. case '3':
  24. $map['status']=$status;
  25. $meta_title="拒绝换货商品";
  26. break;
  27. case '4':
  28. $map['status']=$status;
  29. $meta_title="换货中商品";
  30. break;
  31. case '5':
  32. $map['status']=$status;
  33. $meta_title="完成换货商品";
  34. break;
  35. }
  36. } else {
  37. $status=1;
  38. $meta_title="换货商品管理";
  39. }
  40. if(isset($_GET['title'])){
  41. $condition['title'] = array('like', '%'.(string)I('title').'%');
  42. $data=M('document')->where($condition)->select();
  43. foreach($data as $k=>$val){
  44. //获取购物清单数据表产品id,字段id
  45. $ids=array();
  46. array_push($ids,$val['id']);
  47. }
  48. $map['goodid']=array("in",$ids);
  49. }
  50. if ( isset($_GET['time-start']) ) {
  51. $map['update_time'][] = array('egt',strtotime(I('time-start')));
  52. }
  53. if ( isset($_GET['time-end']) ) {
  54. $map['update_time'][] = array('elt',24*60*60 + strtotime(I('time-end')));
  55. }
  56. if ( isset($_GET['nickname']) ) {
  57. $map['uid'] = M('Member')->where(array('nickname'=>I('nickname')))->getField('uid');
  58. }
  59. $this->meta_title = $meta_title;
  60. $this->assign('status', $status);
  61. /* 查询条件初始化 */
  62. $list = $this->lists('Exchange', $map,'id desc');
  63. $this->assign('list', $list);
  64. // 记录当前列表页的cookie
  65. Cookie('__forward__',$_SERVER['REQUEST_URI']);
  66. $this->display();
  67. }
  68. /**
  69. * 新增换货
  70. */
  71. public function add(){
  72. if(IS_POST){
  73. $Exchange =D('Exchange');
  74. if(false !==$Exchange->update()){
  75. $this->success('新增成功', U('index'));
  76. } else {
  77. $this->error('新增失败');
  78. }
  79. } else {
  80. $this->meta_title = '新增'.get_status_title_bymodel($status,'Exchange').'换货商品';
  81. $this->assign('info',null);
  82. $this->display();
  83. }
  84. }
  85. /**
  86. * 编辑订单
  87. *
  88. */
  89. public function edit($id = 0){
  90. if(IS_POST){
  91. $Exchange =D('Exchange');
  92. if(false !==$Exchange->update()){
  93. //记录行为
  94. $this->success('更新成功', Cookie('__forward__'));
  95. } else {
  96. $this->error('更新失败'.$id);
  97. }
  98. } else {
  99. $info = array();
  100. /* 获取数据 */
  101. $info = M('Exchange')->find($id);
  102. $list=M('Exchange')->where("shopid='$id'")->select();
  103. if(false === $info){
  104. $this->error('获取订单信息错误');
  105. }
  106. $this->assign('list', $list);
  107. $this->assign('info', $info);
  108. $this->meta_title = '编辑订单';
  109. $this->display();
  110. }
  111. }
  112. /**
  113. * 同意换货
  114. */
  115. public function agree($id = 0){
  116. if(IS_POST){
  117. $id=$_POST["id"];
  118. $shopid=$_POST["shopid"];
  119. //销量减1 库存加1
  120. $sales= M('document')->where("id='$id'")->setDec('sale');
  121. $stock= M('document')->where("id='$id'")->setInc('stock'); // yp_document_product
  122. /*更新时间*/
  123. $Exchange =D('Exchange');
  124. if(false !==$Exchange->update()){
  125. $this->success('更新成功', Cookie('__forward__'));
  126. } else {
  127. $this->error('更新失败'.$id);
  128. }
  129. } else {
  130. $info = array();
  131. /* 获取数据 */
  132. $info = M('Exchange')->find($id);
  133. $detail= M('Exchange')->where("id='$id'")->select();
  134. $list=M('shoplist')->where("orderid='$id'")->select();
  135. if(false === $info){
  136. $this->error('获取订单信息错误');
  137. }
  138. $this->assign('list', $list);
  139. $this->assign('detail', $detail);
  140. $this->assign('info', $info);
  141. $this->meta_title = '编辑订单';
  142. $this->display();
  143. }
  144. }
  145. /**
  146. * 拒绝换货
  147. */
  148. public function refuse($id = 0){
  149. if(IS_POST){
  150. $Exchange =D('Exchange');
  151. if(false !==$Exchange->update()){
  152. //记录行为
  153. action_log('update_order', 'order', $data['id'], UID);
  154. $this->success('更新成功', Cookie('__forward__'));
  155. } else {
  156. $this->error('更新失败'.$id);
  157. }
  158. } else {
  159. $info = array();
  160. /* 获取数据 */
  161. $info = M('Exchange')->find($id);
  162. $detail= M('Exchange')->where("id='$id'")->select();
  163. $list=M('shoplist')->where("orderid='$id'")->select();
  164. if(false === $info){
  165. $this->error('获取订单信息错误');
  166. }
  167. $this->assign('list', $list);
  168. $this->assign('detail', $detail);
  169. $this->assign('info', $info);
  170. $this->meta_title = '拒绝退货订单';
  171. $this->display();
  172. }
  173. }
  174. /**
  175. * 编辑换货
  176. */
  177. public function send($id = 0){
  178. if(IS_POST){
  179. $Exchange =D('Exchange');
  180. if(false !==$Exchange->update()){
  181. //记录行为
  182. action_log('update_Exchange', 'Exchange', $data['id'], UID);
  183. $this->success('更新成功', Cookie('__forward__'));
  184. } else {
  185. $this->error('更新失败,退货单'.$id);
  186. }
  187. } else {
  188. $info = array();
  189. $info = M('Exchange')->find($id);
  190. $shopid=$info["shopid"];
  191. $orderid=M('shoplist')->where("id='$shopid'")->getField('orderid');
  192. $addressid=M('order')->where("id='$orderid'")->getField('addressid');
  193. $array = array();
  194. $array = M('address')->find($addressid);
  195. if(false === $info){
  196. $this->error('获取订单信息错误');
  197. }
  198. $this->assign('arr', $array);
  199. $this->assign('info', $info);
  200. $this->meta_title = '编辑订单';
  201. $this->display();
  202. }
  203. }
  204. /**
  205. * 同意换货
  206. */
  207. public function complete($id = 0){
  208. if(IS_POST){
  209. $Exchange =D('Exchange');
  210. if(false !==$Exchange->update()){
  211. //记录行为
  212. action_log('update_order', 'order', $data['id'], UID);
  213. $this->success('更新成功', Cookie('__forward__'));
  214. } else {
  215. $this->error('更新失败'.$id);
  216. }
  217. } else {
  218. $info = array();
  219. $info = M('Exchange')->find($id);
  220. $detail= M('Exchange')->where("id='$id'")->select();
  221. $list=M('shoplist')->where("orderid='$id'")->select();
  222. if(false === $info){
  223. $this->error('获取订单信息错误');
  224. }
  225. $this->assign('list', $list);
  226. $this->assign('detail', $detail);
  227. $this->assign('info', $info);
  228. $this->meta_title = '编辑订单';
  229. $this->display();
  230. }
  231. }
  232. /**
  233. * 删除换货
  234. */
  235. public function del(){
  236. if(IS_POST){
  237. $ids = I('post.id');
  238. $order = M("Exchange");
  239. if(is_array($ids)){
  240. foreach($ids as $id){
  241. $order->where("id='$id'")->delete();
  242. }
  243. }
  244. $this->success("删除成功!");
  245. }else{
  246. $id = I('get.id');
  247. $db = M("Exchange");
  248. $status = $db->where("id='$id'")->delete();
  249. if ($status){
  250. $this->success("删除成功!");
  251. }else{
  252. $this->error("删除失败!");
  253. }
  254. }
  255. }
  256. }