| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace addons\HiGo\backend\controllers;
- use addons\HiGo\common\enums\HiGoEnum;
- use addons\HiGo\common\models\HigoMall;
- use addons\HiGo\common\models\HigoWallet;
- use addons\HiGo\common\models\HigoWalletLog;
- use common\models\user\User;
- use Yii;
- /**
- * 默认控制器
- *
- * Class HiValueController
- * @package addons\HiGo\backend\controllers
- */
- class HiValueController extends BaseController
- {
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- $get = Yii::$app->request->get();
- $user_id = $get['user_id'] ?? 0;
- $keyword = $get['keyword'] ?? '';
- $remark = $get['remark'] ?? '';
- $type = $get['type'] ?? '';
- $filter = [];
- if ($user_id > 0) {
- $filter[] = ['user_id' => $user_id];
- }
- if (!empty($keyword)) {
- $search_user_ids = User::find()->where([
- 'or', ['like', 'nickname', $keyword], ['like', 'mobile', $keyword]
- ])->select(['id'])->asArray()->all();
- $search_user_ids = array_column($search_user_ids, 'id');
- if ($search_user_ids) {
- $filter[] = ['user_id' => $search_user_ids];
- } else {
- $filter[] = ['user_id' => []];
- }
- }
- if (!empty($remark)) {
- $filter[] = ['like', 'desc', $remark];
- }
- if (!empty($type)) {
- $filter[] = ['change_type' => $type];
- }
- $params = [
- 'where' => array_merge([
- ['mall_id' => $this->mall_id],
- ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_VALUE]
- ], $filter),
- 'with' => ['user'],
- 'order' => 'id DESC'
- ];
- $list = HigoWalletLog::listPage($params);
- if ($list === false) {
- return $this->error(HigoWalletLog::getStaticError());
- }
- $from_type_map = HiGoEnum::getFromTypeMap($this->mall_id);
- foreach ($list['list'] as &$item) {
- if($item['addon_name'] == HiGoEnum::ADDONS_NAME){
- $item['from_type'] = $from_type_map[$item['from_type']] ?? '';
- }else{
- $item['from_type'] = HiGoEnum::getAddonsFromTypeMap($item['addon_name'],$item['from_type']);
- }
- $item['before_num'] = $item['change_type'] == 'add' ? bcsub($item['after_num'], $item['change_num'], 2) : bcadd($item['after_num'], $item['change_num'], 2);
- }
- unset($item);
- //总发放嗨值
- $higo_mall = HigoMall::getOne([['mall_id' => $this->mall_id]], true);
- $total = HigoWallet::find()->where(['mall_id' => $this->mall_id])
- ->select('sum(hi_value) as total_hi_value')->asArray()->one();
- $list['orderStatistics'] = [
- 'total_send_hi_zhi' => $higo_mall['hi_value'],
- 'used' => bcsub($higo_mall['hi_value'], $total['total_hi_value'], 10),
- 'unused' => $total['total_hi_value'] ?? 0
- ];
- return $this->success('success', $list);
- }
- return $this->render('index', []);
- }
- }
|