| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace addons\Happiness\common\logic\store;
- use addons\Happiness\common\models\HappinessStore;
- use addons\Happiness\common\models\HappinessStoreCommission;
- use addons\Happiness\common\models\HappinessWithdrawLog;
- use common\enums\StatusEnum;
- use common\models\common\CommissionLog;
- class StoreCensus
- {
- public $mall_id = null;
- public $start = 0;
- public $end = 0;
- public function __construct($mall_id, $start = 0, $end = 0)
- {
- $this->mall_id = $mall_id;
- $this->end = $end;
- $this->start = $start;
- }
- public function getRealPayAmounts()
- {
- $query = HappinessStoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'is_settlement' => [0,1]]);
- if (!empty($this->start)) $query->andWhere(['>=', 'created_at', $this->start]);
- if (!empty($this->end)) $query->andWhere(['<=', 'created_at', $this->end]);
- $realPayAmounts = $query->sum('amount_received');
- return $realPayAmounts ?? 0;
- }
- public function getNotSettleAmounts()
- {
- $query = HappinessStoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'is_settlement' => 0]);
- if (!empty($this->start)) $query->andWhere(['>=', 'created_at', $this->start]);
- if (!empty($this->end)) $query->andWhere(['<=', 'created_at', $this->end]);
- $not_settle_amounts = $query->sum('amount_received');
- return $not_settle_amounts ?? 0;
- }
- public function getSettleAmounts()
- {
- $query = CommissionLog::find()->where(['mall_id' => $this->mall_id, 'source_table' => ['store_order_detail', 'store_cashier_order']]);
- if (!empty($this->start)) $query->andWhere(['>=', 'created_at', $this->start]);
- if (!empty($this->end)) $query->andWhere(['<=', 'created_at', $this->end]);
- $settle_amounts = $query->sum('change_num');
- return $settle_amounts ?? 0;
- }
- public function getPayPeopleNumbers()
- {
- $mall_id = $this->mall_id;
- $start = $this->start;
- $end = $this->end;
- $sql = "select count(*) as counts from (
- select user_id from qimall_addons_happiness_store_commission where mall_id = {$mall_id} and status in(0,1)";
- if (!empty($start)) $sql .= " and created_at >={$start}";
- if (!empty($end)) $sql .= " and created_at <= {$end}";
- $sql .= " group by user_id ) t";
- $result = \Yii::$app->db->createCommand($sql)->queryAll();
- return $result[0]['counts'] ?? 0;
- }
- public function getPayOrderNumbers()
- {
- $query = HappinessStoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (!empty($this->start)) $query->andWhere(['>=', 'created_at', $this->start]);
- if (!empty($this->end)) $query->andWhere(['<=', 'created_at', $this->end]);
- $pay_order_numbers = $query->count();
- return $pay_order_numbers ?? 0;
- }
- public function getWithdrawData()
- {
- $list = HappinessWithdrawLog::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED], ['withdraw_status' => [0, 1]],
- ['>=', 'created_at', $this->start],
- ['<=', 'created_at', $this->end]
- ],
- 'group' => 'withdraw_status',
- 'select' => 'withdraw_status,sum(num) as num'
- ]);
- $waiting_audit_withdraw_amounts = 0;
- $waiting_pay_withdraw_amounts = 0;
- foreach ($list as $item) {
- if ($item['withdraw_status'] == 0) {
- $waiting_audit_withdraw_amounts = $item['num'];
- }
- if ($item['withdraw_status'] == 1) {
- $waiting_pay_withdraw_amounts = $item['num'];
- }
- }
- return [$waiting_audit_withdraw_amounts, $waiting_pay_withdraw_amounts];
- }
- public function getWaitingAuditStoreNumbers()
- {
- $waiting_audit_store_numbers = HappinessStore::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->andWhere(['>=', 'created_at', $this->start])
- ->andWhere(['<=', 'created_at', $this->end])
- ->count();
- return $waiting_audit_store_numbers ?? 0;
- }
- }
|