StoreBossIncome.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: kaifa
  5. * Date: 2020-05-10
  6. * Time: 17:57
  7. */
  8. namespace addons\Store\common\models;
  9. use common\models\order\CommonOrderDetail;
  10. use common\models\order\PriceLog;
  11. use common\models\user\User;
  12. use addons\Store\common\models\BossLevelCommon;
  13. use addons\Store\common\models\Boss;
  14. use addons\Store\common\models\BossPriceLog;
  15. use addons\Store\common\models\BossLevel;
  16. use addons\Store\common\models\BossOrderGoodsLog;
  17. use addons\Store\common\models\BossPriceLogType;
  18. use addons\Store\common\models\BossSetting;
  19. use addons\Boss\common\enums\LevelEnum;
  20. use common\enums\StatusEnum;
  21. use addons\Boss\common\models\AddonsBossCommissionLog;
  22. use yii\data\Pagination;
  23. class StoreBossIncome extends BaseModel
  24. {
  25. public $keyword;
  26. public $id;
  27. public $platform;
  28. public $limit = 10;
  29. public $page = 1;
  30. public $sort;
  31. public $fields;
  32. public $flag;
  33. public $store_id = 0;
  34. public function rules()
  35. {
  36. return [
  37. [['keyword', 'platform'], 'trim'],
  38. [['keyword', 'platform', 'flag'], 'string'],
  39. [['limit', 'page','id','store_id'], 'integer'],
  40. [['fields'], 'safe'],
  41. [['sort'], 'default', 'value' => ['l.created_at' => SORT_DESC]],
  42. ];
  43. }
  44. /**
  45. * 明细列表
  46. * @return array
  47. */
  48. public function getList($params)
  49. {
  50. if (!$this->validate()) {
  51. return $this->responseErrorInfo();
  52. }
  53. // $boss_level_list = AddonsBossLevel::getBossLevel([['mall_id' => $store['mall_id']]], [],true,'level,name');
  54. $boss_level_list = (new \addons\Store\common\models\StoreBossLevelCommon)->getList();
  55. $boss_level_arr = array_column($boss_level_list, null,'level');
  56. $settlement_method = LevelEnum::getSettlementMethod();// 结算方式
  57. $compute_type = LevelEnum::getComputeType();// 佣金计算方式
  58. // 获取用户信息
  59. $user = User::find()->select('nickname,avatar_url')->where(['mall_id' => $params['mall_id'],'id' => $params['id']])->asArray()->one();
  60. $where = [];
  61. $where[] = ['=', 'mall_id', $params['mall_id']];
  62. // $where[] = ['=', 'store_id', $params['store_id']];
  63. $where[] = ['=', 'user_id', $params['id']];
  64. $where[] = ['=', 'type', $params['type']];
  65. $where[] = ['between', 'date', str_replace('-','',$params['start_time']), str_replace('-','',$params['end_time'])];
  66. $where[] = ['=', 'is_settlement', StatusEnum::ENABLED];
  67. $where[] = ['=', 'status', StatusEnum::ENABLED];
  68. $order = 'created_at desc';
  69. $params = array('where' => $where, 'order' => $order, 'limit' => 20);
  70. $list = StoreBossRewardLog::listPage($params, false, true);
  71. return [
  72. 'code' => 0,
  73. 'msg' => '获取成功',
  74. 'data' => [
  75. 'list' => $list,
  76. 'boss_level_arr' => $boss_level_arr,
  77. 'user'=>$user,
  78. 'settlement_method' => $settlement_method,
  79. 'compute_type' => $compute_type,
  80. ]
  81. ];
  82. }
  83. /**
  84. * 结算列表
  85. * @return array
  86. */
  87. public function getSettlementList($params)
  88. {
  89. if (!$this->validate()) {
  90. return $this->responseErrorInfo();
  91. }
  92. $store = \Yii::$app->session->get('o2o');
  93. $commonission_type = LevelEnum::getCommissionType();// 分红类型
  94. $compute_period = LevelEnum::getComputePeriod();// 分红周期
  95. $where = [];
  96. $where[] = ['=', 'mall_id', $store['mall_id']];
  97. $where[] = ['=', 'store_id', $store['id']];
  98. // 根据用户昵称搜索
  99. if (isset($params['keyword'])) {
  100. $where[] = ['=', 'user_id', $params['keyword']];
  101. // $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id,'mobile' => $params['keyword'],'status' => StatusEnum::ENABLED])->asArray()->scalar();
  102. // if ($user_id) $where[] = ['=', 'user_id', $user_id];
  103. }
  104. $where[] = ['=', 'status', StatusEnum::ENABLED];
  105. $where[] = ['in', 'source', [StoreBossRewardLog::SOURCE_ORDER_STORE,StoreBossRewardLog::SOURCE_CASHIER_STORE]];
  106. $order = 'created_at desc';
  107. $with = ['user'];
  108. $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => 20);
  109. $list = StoreBossCommissionLog::listPage($params, false, true);
  110. if (empty($list)){
  111. return [
  112. 'code' => 0,
  113. 'msg' => '',
  114. 'data' => []
  115. ];
  116. }
  117. foreach ($list['list'] as &$item) {
  118. $item['start_time'] = date("Y-m-d", $item['start_time']);
  119. $item['end_time'] = date("Y-m-d", $item['end_time']);
  120. }
  121. return [
  122. 'code' => 0,
  123. 'msg' => '',
  124. 'data' => [
  125. 'list' => $list,
  126. 'commonission_type' => $commonission_type,
  127. 'compute_period' => $compute_period,
  128. ]
  129. ];
  130. }
  131. }