/Application/Admin/Controller/ChangeController.class.php

https://gitlab.com/xuebutayan/yshop · PHP · 301 lines · 211 code · 40 blank · 50 comment · 38 complexity · 976ae4dad484d0e0f5e7a1c08c3e6535 MD5 · raw file

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