ApplySeller.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\store\model;
  13. use app\common\model\ApplySeller as ApplySellerModel;
  14. use app\console\model\user\CommissionsDetail;
  15. /**
  16. * 配送模板模型
  17. * Class Delivery
  18. * @package app\common\model
  19. */
  20. class ApplySeller extends ApplySellerModel
  21. {
  22. /**
  23. * 隐藏字段
  24. * @var array
  25. */
  26. protected $hidden = [
  27. 'is_delete',
  28. 'store_id',
  29. //'update_time'
  30. ];
  31. public function getList($conditions){
  32. $model = new self;
  33. $from = 1633017600 ;$to = time();
  34. if ($conditions and count($conditions)){
  35. foreach ($conditions as $key=>$c){
  36. if ($key =='betweenTime'){
  37. if (isset($c[0]) && $c[0] && isset($c[1]) && $c[1]){
  38. $times = between_time($c);
  39. $from = $times['start_time'];
  40. $to = $times['end_time'] + 86400;
  41. }
  42. }
  43. if ($key == "mobile" && trim($c,' ')){
  44. $model = $model->whereLike($key,'%'.$c.'%');
  45. }
  46. }
  47. if ($from && $to){
  48. $model = $model->whereBetweenTime('create_time',$from,$to);
  49. }
  50. }
  51. return $model->where('is_delete',0)
  52. ->field('id,user_id,nick_name,mobile,create_time,update_time,state,seller_grade,invite_code')
  53. ->order('state','asc')->order('create_time','desc')
  54. ->paginate(15)->each(function($item){
  55. $item->sale_volume = 0.00;
  56. $item->inviter_sale_volume = 0.00;
  57. if ($item->state == 1){
  58. $user = User::where('user_id',$item->user_id)->find();
  59. if ($user){
  60. $from = strtotime('-1 year',$user->seller_expire);
  61. $wheres[] = ['user_id','=',$item->user_id];
  62. $wheres[] = ['shop_id','=',0];
  63. $wheres[] = ['role','=',User::COMMISSION_USER];
  64. $wheres[] = ['commission_level','=',1];
  65. $wheres[] = ['order_create_time','>=',$from];
  66. $wheres[] = ['order_create_time','<=',$user->seller_expire];
  67. $wheres[] = ['clearing_status','<',2];
  68. $item->sale_volume = CommissionsDetail::sumOrderSaleVolume($wheres);
  69. /* $orderGoodsId = CommissionsDetail::getCommOrderGoodsId($item->user_id,$from,$user->seller_expire);
  70. $item->sale_volume = \app\console\model\OrderGoods::sumOrderGoodsVolume($orderGoodsId);*/
  71. }
  72. $user_ids = User::where("upper_user_id",$item->user_id)->where('role',99)->column('user_id');
  73. if($user_ids){
  74. $wheres[] = ['user_id','in',$user_ids];
  75. $wheres[] = ['shop_id','=',0];
  76. $wheres[] = ['role','=',User::COMMISSION_USER];
  77. $wheres[] = ['commission_level','=',1];
  78. $wheres[] = ['clearing_status','<',2];
  79. $item->inviter_sale_volume = CommissionsDetail::sumOrderSaleVolume($wheres);
  80. }
  81. }
  82. //下级推荐官数
  83. $item['inviter_cnt'] = User::where("upper_user_id",$item->user_id)->where('role',User::COMMISSION_USER)->count();
  84. //下级用户数
  85. $item['inviter_users'] = User::where("upper_user_id",$item->user_id)->where('role',User::NORMAL_USER)->count();
  86. })->toArray();
  87. }
  88. public function edit($data){
  89. if (!isset($data['id']))return false;
  90. $m = self::find($data['id']);
  91. $m->state = $data['state'];
  92. $m->seller_grade = 1;
  93. $m->refuse_reason = $data['refuse_reason']??'';
  94. $m->save();
  95. //self::where('id',$data['id'])->update(['state'=>$data['state'],'seller_grade'=>1,'refuse_reason'=>$data['refuse_reason']??'']);
  96. if ($data['state'] == 1 && isset($data['user_id'])){
  97. $seller_expire = strtotime('+1 year');
  98. User::where('user_id',intval($data['user_id']))->update(['role'=>99,'seller_grade'=>1,'seller_expire'=>$seller_expire]);
  99. }
  100. return true;
  101. }
  102. }