SaleUser.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 app\common\controller\Manage;
  10. use app\popupshop\model\Sale;
  11. use app\popupshop\model\SaleUser as AppSaleUser;
  12. use think\facade\Request;
  13. use think\helper\Time;
  14. class SaleUser extends Manage{
  15. public function initialize() {
  16. parent::initialize();
  17. $this->assign('pathMaps',[['name'=>'客户商品','url'=>url("popupshop/saleUser/index")]]);
  18. }
  19. /**
  20. * 列表
  21. */
  22. public function index(){
  23. $time = Request::param('time/d', 0);
  24. $uid = Request::param('uid/d');
  25. $starttime = Request::param('starttime/s');
  26. $endtime = Request::param('endtime/s');
  27. $condition[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  28. if($time){
  29. switch ($time) {
  30. case 2:
  31. list($start, $end) = Time::yesterday();
  32. break;
  33. case 30:
  34. list($start, $end) = Time::month();
  35. break;
  36. case 60:
  37. list($start, $end) = Time::lastMonth();
  38. break;
  39. default:
  40. list($start, $end) = Time::today();
  41. break;
  42. }
  43. $condition[] = ['update_time','>=',$start];
  44. $condition[] = ['update_time','<=',$end];
  45. }else{
  46. if($starttime){
  47. $condition[] = ['update_time','>=',strtotime($starttime)];
  48. }
  49. if($endtime){
  50. $condition[] = ['update_time','<=',strtotime($endtime)];
  51. }
  52. }
  53. if($uid){
  54. $condition[] = ['user_id','=',$uid];
  55. }
  56. $view['status'] = Request::param('status', 0);
  57. $view['lists'] = AppSaleUser::where($condition)->order('id desc')->paginate(20, false, ['query' => ['status' => $view['status']]]);
  58. $view['count'] = AppSaleUser::where($condition)->count();
  59. $view['money'] = AppSaleUser::where($condition)->sum('rebate');
  60. $view['time'] = $time;
  61. $view['uid'] = $uid;
  62. $view['starttime'] = $starttime;
  63. $view['endtime'] = $endtime;
  64. return view()->assign($view);
  65. }
  66. /**
  67. * 删除
  68. */
  69. public function delete(){
  70. $id = $this->request->param('id');
  71. if(empty($id)){
  72. return enjson(0);
  73. }
  74. Sale::where(['member_miniapp_id' => $this->member_miniapp_id,'sales_user_id' => $id])->delete(); //删除已上架套装
  75. AppSaleUser::destroy($id);
  76. return enjson(200);
  77. }
  78. }