HiValueController.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace addons\HiGo\backend\controllers;
  3. use addons\HiGo\common\enums\HiGoEnum;
  4. use addons\HiGo\common\models\HigoMall;
  5. use addons\HiGo\common\models\HigoWallet;
  6. use addons\HiGo\common\models\HigoWalletLog;
  7. use common\models\user\User;
  8. use Yii;
  9. /**
  10. * 默认控制器
  11. *
  12. * Class HiValueController
  13. * @package addons\HiGo\backend\controllers
  14. */
  15. class HiValueController extends BaseController
  16. {
  17. /**
  18. * 首页
  19. *
  20. * @return string
  21. */
  22. public function actionIndex()
  23. {
  24. if (Yii::$app->request->isAjax) {
  25. $get = Yii::$app->request->get();
  26. $user_id = $get['user_id'] ?? 0;
  27. $keyword = $get['keyword'] ?? '';
  28. $remark = $get['remark'] ?? '';
  29. $type = $get['type'] ?? '';
  30. $filter = [];
  31. if ($user_id > 0) {
  32. $filter[] = ['user_id' => $user_id];
  33. }
  34. if (!empty($keyword)) {
  35. $search_user_ids = User::find()->where([
  36. 'or', ['like', 'nickname', $keyword], ['like', 'mobile', $keyword]
  37. ])->select(['id'])->asArray()->all();
  38. $search_user_ids = array_column($search_user_ids, 'id');
  39. if ($search_user_ids) {
  40. $filter[] = ['user_id' => $search_user_ids];
  41. } else {
  42. $filter[] = ['user_id' => []];
  43. }
  44. }
  45. if (!empty($remark)) {
  46. $filter[] = ['like', 'desc', $remark];
  47. }
  48. if (!empty($type)) {
  49. $filter[] = ['change_type' => $type];
  50. }
  51. $params = [
  52. 'where' => array_merge([
  53. ['mall_id' => $this->mall_id],
  54. ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_VALUE]
  55. ], $filter),
  56. 'with' => ['user'],
  57. 'order' => 'id DESC'
  58. ];
  59. $list = HigoWalletLog::listPage($params);
  60. if ($list === false) {
  61. return $this->error(HigoWalletLog::getStaticError());
  62. }
  63. $from_type_map = HiGoEnum::getFromTypeMap($this->mall_id);
  64. foreach ($list['list'] as &$item) {
  65. if($item['addon_name'] == HiGoEnum::ADDONS_NAME){
  66. $item['from_type'] = $from_type_map[$item['from_type']] ?? '';
  67. }else{
  68. $item['from_type'] = HiGoEnum::getAddonsFromTypeMap($item['addon_name'],$item['from_type']);
  69. }
  70. $item['before_num'] = $item['change_type'] == 'add' ? bcsub($item['after_num'], $item['change_num'], 2) : bcadd($item['after_num'], $item['change_num'], 2);
  71. }
  72. unset($item);
  73. //总发放嗨值
  74. $higo_mall = HigoMall::getOne([['mall_id' => $this->mall_id]], true);
  75. $total = HigoWallet::find()->where(['mall_id' => $this->mall_id])
  76. ->select('sum(hi_value) as total_hi_value')->asArray()->one();
  77. $list['orderStatistics'] = [
  78. 'total_send_hi_zhi' => $higo_mall['hi_value'],
  79. 'used' => bcsub($higo_mall['hi_value'], $total['total_hi_value'], 10),
  80. 'unused' => $total['total_hi_value'] ?? 0
  81. ];
  82. return $this->success('success', $list);
  83. }
  84. return $this->render('index', []);
  85. }
  86. }