| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <?php
- namespace addons\Boss\backend\controllers;
- use addons\Boss\common\enums\BossEnum;
- use addons\Boss\common\enums\LevelEnum;
- use addons\Boss\common\models\AddonsBoss;
- use addons\Boss\common\models\AddonsBossCommissionLog;
- use addons\Boss\common\models\AddonsBossLevel;
- use addons\Boss\common\models\AddonsBossRewardLog;
- use common\enums\StatusEnum;
- use common\models\base\User;
- use Yii;
- use common\controllers\AddonsController;
- /**
- * 结算明细控制器
- *
- * Class CommissionController
- * @package addons\Boss\backend\controllers
- */
- class CommissionController extends AddonsController
- {
- /**
- * @var string
- */
- // public $layout = "@addons/Boss/backend/views/layouts/main";
- public $enableCsrfValidation = false;
- /**
- * 结算周期明细列表
- * @Author: lun
- * @DateTime: 2021/10/23 0023 10:14
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionIndex()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isPost) {
- // 检查提交的参数
- $params = $retuest->post();
- $res = Yii::$app->services->validate->validate($params,[
- [['page','limit'], 'integer'],
- [['keyword'], 'string']
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $commonission_type = LevelEnum::getCommissionType();// 分红类型
- $compute_period = LevelEnum::getComputePeriod();// 分红周期
- $is_sediment = Yii::$app->services->setting->addons->get($this->mall_id, BossEnum::ADDONS_NAME, 'basic.is_sediment');// 分红周期
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- // 根据用户昵称搜索
- if (isset($params['keyword'])) {
- $where[] = ['=', 'user_id', $params['keyword']];
- // $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id,'mobile' => $params['keyword'],'status' => StatusEnum::ENABLED])->asArray()->scalar();
- // if ($user_id) $where[] = ['=', 'user_id', $user_id];
- }
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'id desc,created_at desc';
- $with = ['user'];
- $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $params['limit']);
- $list = AddonsBossCommissionLog::listPage($params, false, true);
- if (empty($list)) $this->error('获取失败');
- foreach ($list['list'] as &$item) {
- $item['start_time'] = date("Y-m-d", strtotime($item['start_time']));
- $item['end_time'] = date("Y-m-d", strtotime($item['end_time']));
- }
- $this->success('获取成功', compact('list', 'commonission_type', 'compute_period','is_sediment'));
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 分红明细
- * @Author: lun
- * @DateTime: 2021/11/5 0005 16:58
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionRewardLog()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isPost) {
- // 检查提交的参数
- $params = $retuest->post();
- $res = Yii::$app->services->validate->validate($params,[
- [['id','type','start_time','end_time'], 'required'],
- [['id','type'], 'integer'],
- [['start_time','end_time'], 'string']
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 获取股东等级
- $boss_level_list = AddonsBossLevel::getBossLevel([['mall_id' => $this->mall_id]], [],true,'level,name');
- $boss_level_arr = array_column($boss_level_list, null,'level');
- $settlement_method = LevelEnum::getSettlementMethod();// 结算方式
- $compute_type = LevelEnum::getComputeType();// 佣金计算方式
- // 获取用户信息
- $user = User::find()->select('nickname,avatar_url')->where(['mall_id' => $this->mall_id,'id' => $params['id']])->asArray()->one();
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'user_id', $params['id']];
- $where[] = ['=', 'type', $params['type']];
- $where[] = ['between', 'date', str_replace('-','',$params['start_time']), str_replace('-','',$params['end_time'])];
- $where[] = ['=', 'is_settlement', StatusEnum::ENABLED];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'created_at desc';
- $params = array('where' => $where, 'order' => $order, 'limit' => $params['limit']);
- $list = AddonsBossRewardLog::listPage($params, false, true);
- foreach($list['list'] as $key => $value){
- $value['settlement_config'] = json_decode($value['settlement_config'],true);
- $value['settlement_config']['order_type'] = '商城订单';
- if(isset($value['settlement_config']['order_source']) && $value['settlement_config']['store_id']){
- $value['settlement_config']['order_type'] = $value['settlement_config']['order_source'] == 'store_order' ? '门店订单,门店ID:'.$value['settlement_config']['store_id'] : '门店收银订单,门店ID:'.$value['settlement_config']['store_id'];
- }
- if(!empty($value['settlement_config']['order_source']) && !empty($value['settlement_config']['mch_id'])){
- $value['settlement_config']['order_type'] = '多商户订单';
- }
- $value['settlement_config'] = json_encode($value['settlement_config']);
- $value['commission_type_msg'] = '(元)';
- if(in_array($value['type'],[LevelEnum::DIGITAL_PRIZE,LevelEnum::EXTRA_DIGITAL_PRIZE])){
- $value['commission_type_msg'] = '(数字币)';
- }
- $list['list'][$key] = $value;
- }
- $this->success('获取成功', compact('list','boss_level_arr', 'user', 'settlement_method' ,'compute_type'));
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 手动执行
- * @Author: lun
- * @DateTime: 2022/9/14 0014 14:41
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- public function actionHandleJob()
- {
- try {
- $get = Yii::$app->request->get();
- $start_day = $get['start_day'] ?: date('Ymd');
- $end_day = $get['end_day'] ?: date('Ymd');
- $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Boss', 'basic');
- $logic = new \addons\Boss\common\logic\CommissionLogLogic();
- $res = $logic->addCommissionLog($this->mall_id, $config, $start_day, $end_day);
- if ($res === false) throw new \Exception($logic->getError());
- echo '执行成功';
- exit;
- } catch (\Exception $e) {
- echo '错误原因:'.$e->getMessage();
- exit;
- }
- }
- /**
- * 待结算明细
- * @Author: lun
- * @DateTime: 2023/7/18 0018 17:33
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionUnsettled()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- // 检查提交的参数
- $params = $retuest->get();
- $res = Yii::$app->services->validate->validate($params,[
- [['user_id', 'type', 'is_settlement', 'page', 'limit'], 'integer'],
- [['order_no'], 'string']
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $commonission_type = LevelEnum::getCommissionType();// 分红类型
- $boss_levels = AddonsBossLevel::getLevelByColumn($this->mall_id);// 股东等级
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- // 根据条件搜索
- if (isset($params['user_id'])) $where[] = ['=', 'user_id', $params['user_id']];
- if (isset($params['order_no'])) $where[] = ['=', 'order_no', $params['order_no']];
- if (isset($params['type'])) $where[] = ['=', 'type', $params['type']];
- if (isset($params['is_settlement'])) $where[] = ['=', 'is_settlement', $params['is_settlement']];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'id desc';
- $with = ['user'];
- $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $params['limit']);
- $list = AddonsBossRewardLog::listPage($params, false, true);
- if (empty($list)) $this->error('获取失败');
- $this->success('获取成功', compact('list', 'commonission_type', 'boss_levels'));
- }
- }
- return $this->render($this->action->id);
- }
- }
|