StoreCensus.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace addons\Store\common\logic\store;
  3. use addons\Store\common\enums\StoreEnum;
  4. use addons\Store\common\models\Store;
  5. use addons\Store\common\models\StoreCommission;
  6. use addons\Store\common\models\StoreWithdrawLog;
  7. use common\enums\StatusEnum;
  8. use common\models\common\CommissionLog;
  9. class StoreCensus
  10. {
  11. public $mall_id = null;
  12. public $start = 0;
  13. public $end = 0;
  14. public function __construct($mall_id, $start = 0, $end = 0)
  15. {
  16. $this->mall_id = $mall_id;
  17. $this->end = $end;
  18. $this->start = $start;
  19. }
  20. public function getRealPayAmounts()
  21. {
  22. $query = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  23. if (!empty($this->start)) $query->andWhere(['>=', 'created_at', $this->start]);
  24. if (!empty($this->end)) $query->andWhere(['<=', 'created_at', $this->end]);
  25. $realPayAmounts = $query->sum('amount_received');
  26. return $realPayAmounts ?? 0;
  27. }
  28. public function getNotSettleAmounts()
  29. {
  30. $query = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'is_settlement' => 0]);
  31. if (!empty($this->start)) $query->andWhere(['>=', 'created_at', $this->start]);
  32. if (!empty($this->end)) $query->andWhere(['<=', 'created_at', $this->end]);
  33. $not_settle_amounts = $query->sum('amount_received');
  34. return $not_settle_amounts ?? 0;
  35. }
  36. public function getSettleAmounts()
  37. {
  38. $query = CommissionLog::find()->where(['mall_id' => $this->mall_id, 'source_table' => ['store_order_detail', 'store_cashier_order']]);
  39. if (!empty($this->start)) $query->andWhere(['>=', 'created_at', $this->start]);
  40. if (!empty($this->end)) $query->andWhere(['<=', 'created_at', $this->end]);
  41. $settle_amounts = $query->sum('change_num');
  42. return $settle_amounts ?? 0;
  43. }
  44. public function getPayPeopleNumbers()
  45. {
  46. $mall_id = $this->mall_id;
  47. $start = $this->start;
  48. $end = $this->end;
  49. $sql = "select count(*) as counts from (
  50. select user_id from qimall_addons_store_commission where mall_id = {$mall_id} and status in(0,1)";
  51. if (!empty($start)) $sql .= " and created_at >={$start}";
  52. if (!empty($end)) $sql .= " and created_at <= {$end}";
  53. $sql .= " group by user_id ) t";
  54. $result = \Yii::$app->db->createCommand($sql)->queryAll();
  55. return $result[0]['counts'] ?? 0;
  56. }
  57. public function getPayOrderNumbers()
  58. {
  59. $query = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  60. if (!empty($this->start)) $query->andWhere(['>=', 'created_at', $this->start]);
  61. if (!empty($this->end)) $query->andWhere(['<=', 'created_at', $this->end]);
  62. $pay_order_numbers = $query->count();
  63. return $pay_order_numbers ?? 0;
  64. }
  65. public function getWithdrawData()
  66. {
  67. $list = StoreWithdrawLog::lists([
  68. 'where' => [
  69. ['mall_id' => $this->mall_id],
  70. ['status' => StatusEnum::ENABLED], ['withdraw_status' => [0, 1]],
  71. ['>=', 'created_at', $this->start],
  72. ['<=', 'created_at', $this->end]
  73. ],
  74. 'group' => 'withdraw_status',
  75. 'select' => 'withdraw_status,sum(num) as num'
  76. ]);
  77. $waiting_audit_withdraw_amounts = 0;
  78. $waiting_pay_withdraw_amounts = 0;
  79. foreach ($list as $item) {
  80. if ($item['withdraw_status'] == 0) {
  81. $waiting_audit_withdraw_amounts = $item['num'];
  82. }
  83. if ($item['withdraw_status'] == 1) {
  84. $waiting_pay_withdraw_amounts = $item['num'];
  85. }
  86. }
  87. return [$waiting_audit_withdraw_amounts, $waiting_pay_withdraw_amounts];
  88. }
  89. public function getWaitingAuditStoreNumbers()
  90. {
  91. $waiting_audit_store_numbers = Store::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'check_status' => StoreEnum::CHECK_WAITING])
  92. ->andWhere(['>=', 'created_at', $this->start])
  93. ->andWhere(['<=', 'created_at', $this->end])
  94. ->count();
  95. return $waiting_audit_store_numbers ?? 0;
  96. }
  97. }