SaleOrder.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 订单管理
  7. */
  8. namespace app\popupshop\controller;
  9. use think\facade\Request;
  10. use app\common\controller\Manage;
  11. use app\popupshop\model\SaleOrder as AppSaleOrder;
  12. use app\popupshop\model\SaleOrderCache;
  13. class SaleOrder extends Manage{
  14. public function initialize() {
  15. parent::initialize();
  16. $this->assign('pathMaps',[['name'=>'订单管理','url'=>url("popupshop/saleOrder/index")]]);
  17. }
  18. /**
  19. * 订单库
  20. * @return void
  21. */
  22. protected function orderList(){
  23. $starttime = Request::param('starttime');
  24. $endtime = Request::param('endtime');
  25. if(!empty($starttime) && !empty($endtime)){
  26. $starttime = strtotime(date('Y-m-d 00:00:00',strtotime($starttime)));
  27. $endtime = strtotime(date('Y-m-d 23:59:59',strtotime($endtime)));
  28. if($starttime > $endtime){
  29. $this->error('开始日期不能大于结束日期');
  30. }
  31. if($endtime-$starttime >= 518401){
  32. $this->error('只支持连续6天的查找');
  33. }
  34. }
  35. $view['keyword'] = Request::param('keyword');
  36. $view['status'] = Request::param('status/d',0);
  37. $path[] = ['name'=>'订单管理','url'=>url("popupshop/saleOrder/index")];
  38. $condition = [];
  39. if(!empty($starttime) && !empty($endtime)){
  40. $condition[] = ['order_starttime','>=',$starttime];
  41. $condition[] = ['order_starttime','<=',$endtime];
  42. }
  43. if(!empty($view['keyword'])){
  44. $condition = [['order_no','=',trim($view['keyword'])]];
  45. }
  46. $condition[] = ['member_miniapp_id','=',$this->member_miniapp_id];
  47. $view['count'] = AppSaleOrder::where($condition)->count();
  48. $view['payment'] = AppSaleOrder::where($condition)->where(['paid_at' => 1, 'is_del' => 0])->sum('order_amount');
  49. $view['no_payment'] = AppSaleOrder::where($condition)->where(['paid_at' => 0, 'is_del' => 0])->sum('order_amount');
  50. switch ($view['status']) {
  51. case 1:
  52. $condition[] = ['paid_at','=',0];
  53. $condition[] = ['is_del','=',0];
  54. $path[] = ['name'=>'未付款','url'=>'javascript:;'];
  55. break;
  56. case 2:
  57. $condition[] = ['paid_at','=',1];
  58. $condition[] = ['is_del','=',0];
  59. $path[] = ['name'=>'已付款','url'=>'javascript:;'];
  60. break;
  61. case 3:
  62. $condition[] = ['express_status','=',1];
  63. $condition[] = ['is_del','=',0];
  64. $condition[] = ['status','=',0];
  65. $path[] = ['name'=>'已发货','url'=>'javascript:;'];
  66. break;
  67. case 4:
  68. $condition[] = ['is_del','=',1];
  69. $path[] = ['name'=>'回收站','url'=>'javascript:;'];
  70. break;
  71. case 5:
  72. $condition[] = ['status','=',1];
  73. $condition[] = ['is_del','=',0];
  74. $path[] = ['name'=>'已结单','url'=>'javascript:;'];
  75. break;
  76. default:
  77. $condition[] = ['is_del','=',0];
  78. break;
  79. }
  80. $view['lists'] = AppSaleOrder::where($condition)->order('id desc')->paginate(10);
  81. $order = [];
  82. foreach ($view['lists'] as $key => $value) {
  83. $order[$key] = AppSaleOrder::order_data($value);
  84. }
  85. $view['order'] = $order;
  86. $view['starttime'] = empty($starttime) ? time() : $starttime;
  87. $view['endtime'] = empty($endtime) ? time() : $endtime;;
  88. $view['pathMaps'] = $path;
  89. return $view;
  90. }
  91. /**
  92. * 订单列表
  93. */
  94. public function index(){
  95. return view()->assign(self::orderList());
  96. }
  97. /**
  98. * 导出Excel
  99. * @return void
  100. */
  101. public function excel(){
  102. header("Content-type: text/plain");
  103. header("Accept-Ranges: bytes");
  104. header("Content-type:application/vnd.ms-excel");
  105. header("Content-Disposition:attachment;filename=Order_".date('Y-m-d').".xls");
  106. header("Pragma: no-cache");
  107. header("Expires: 0");
  108. return view()->assign(self::orderList());
  109. }
  110. /**
  111. * 订单预览
  112. */
  113. public function view(){
  114. $order_no = Request::param('order_no');
  115. $view['order'] = AppSaleOrder::order_data(AppSaleOrder::where(['member_miniapp_id' => $this->member_miniapp_id,'order_no' => $order_no])->find());
  116. return view()->assign($view);
  117. }
  118. /**
  119. * 发货
  120. */
  121. public function sendgoods(){
  122. if(request()->isAjax()){
  123. $data = [
  124. 'order_no' => Request::param('order_no/s'),
  125. 'express_company' => Request::param('express_company/s'),
  126. 'express_no' => Request::param('express_no/s'),
  127. ];
  128. $validate = $this->validate($data,'Order.sendgoods');
  129. if(true !== $validate){
  130. return enjson(0,$validate);
  131. }
  132. //判断当前商品是否完成
  133. $result = AppSaleOrder::where(['paid_at' => 1,'order_no' => $data['order_no']])->find();
  134. if(empty($result)){
  135. return json(['code'=>0,'msg'=>'商品没有满足发货条件']);
  136. }
  137. $data['express_company'] = $data['express_company'];
  138. $data['express_no'] = $data['express_no'];
  139. $data['express_status'] = 1;
  140. $data['express_starttime'] = time();
  141. $rel = AppSaleOrder::where(['id' => $result->id])->update($data);
  142. if($rel){
  143. return enjson(200,'操作成功',['url' => url('popupshop/saleOrder/index',['order_no' => $data['order_no']])]);
  144. }
  145. return enjson(0);
  146. }else{
  147. $order_no = Request::param('order_no/s');
  148. $view['order'] = AppSaleOrder::order_data(AppSaleOrder::where(['member_miniapp_id' => $this->member_miniapp_id,'order_no' => $order_no])->find());
  149. if(empty($view['order'])){
  150. $this->error("404 NOT FOUND");
  151. }
  152. $view['order_no'] = $order_no;
  153. return view()->assign($view);
  154. }
  155. }
  156. /**
  157. * 后台人工修改订单为已发货
  158. */
  159. public function paid(){
  160. $order_no = Request::param('order_no');
  161. $result = AppSaleOrder::where(['paid_at' => 0,'order_no' => $order_no])->update(['paid_at' => 1,'payment_id' => 0,'order_starttime' => time(),'paid_no' => 'GM'.order_no()]);
  162. if($result){
  163. return enjson(200,'操作成功',['url' => url('popupshop/saleOrder/index',['order_no' => $order_no,'status' => Request::param('status/d',0)])]);
  164. }
  165. return enjson(0);
  166. }
  167. /**
  168. * 删除
  169. */
  170. public function delete($order_no){
  171. $rel = AppSaleOrder::where(['order_no' => $order_no])->find();
  172. if($rel){
  173. if($rel['is_del'] == 0){
  174. $result = AppSaleOrder::update(['is_del'=>1],['order_no' => $order_no]);
  175. }else{
  176. $result = AppSaleOrder::where(['order_no' => $order_no])->delete();
  177. if($result){
  178. SaleOrderCache::where(['order_no' => $order_no])->delete();
  179. }
  180. }
  181. if($result){
  182. return enjson(200,'操作成功',['url' => url('popupshop/saleOrder/index',['status' => Request::param('status/d',0)])]);
  183. }
  184. }
  185. return enjson(0);
  186. }
  187. /**
  188. * 清空回收站
  189. */
  190. public function alldelete(){
  191. $rel = AppSaleOrder::where(['is_del'=>1])->select();
  192. if($rel){
  193. foreach ($rel as $value) {
  194. AppSaleOrder::where(['order_no' => $value['order_no']])->delete();
  195. SaleOrderCache::where(['order_no' => $value['order_no']])->delete();
  196. }
  197. return enjson(200,'操作成功',['url' => url('popupshop/saleOrder/index',['status' => Request::param('status/d',0)])]);
  198. }
  199. return enjson(0);
  200. }
  201. /**
  202. * 确认收货
  203. */
  204. public function completion(){
  205. $order_no = Request::param('order_no');
  206. $result = AppSaleOrder::update(['status'=>1],['express_status'=>1,'paid_at' => 1,'order_no' => $order_no]);
  207. if($result){
  208. return enjson(200,'操作成功',['url' => url('popupshop/saleOrder/index',['order_no' => $order_no,'status' => Request::param('status/d',0)])]);
  209. }else{
  210. return enjson(0);
  211. }
  212. }
  213. /**
  214. * 订单完成
  215. */
  216. public function force_completion(){
  217. $order_no = Request::param('order_no');
  218. $result = AppSaleOrder::update(['status'=>1],['order_no' => $order_no,'paid_at' => 0]);
  219. if($result){
  220. return enjson(200,'操作成功',['url' => url('popupshop/saleOrder/index',['order_no' => $order_no,'status' => Request::param('status/d',0)])]);
  221. }else{
  222. return enjson(0);
  223. }
  224. }
  225. }