UserInfo.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <?php
  2. namespace common\models\user;
  3. use addons\Agent\common\models\Agent;
  4. use addons\AgentBase\common\models\AgentBase;
  5. use addons\BonusPool\common\models\BonusPoolUserWallet;
  6. use addons\ConsumerCoupons\common\models\ConsumerCouponsWallet;
  7. use addons\CardCoupons\common\models\CardCouponsScoreGive;
  8. use addons\ContributionCurrency\common\models\ContributionWallet;
  9. use addons\BottleCoupon\common\enums\BottleCouponEnum;
  10. use addons\Coupon\common\models\AddonsCoupon;
  11. use addons\Coupon\common\models\AddonsCouponUserRelate;
  12. use addons\EnergyValue\common\enums\EnergyValueEnum;
  13. use addons\FrozenPerkAsset\common\models\FrozenPerkAsset;
  14. use addons\HiGo\common\logic\WalletLogic;
  15. use addons\HiGo\common\models\HigoWallet;
  16. use addons\NiBao\common\enums\NiBaoEnum;
  17. use addons\NiBao\common\models\NibaoWallet;
  18. use addons\NiBaoEquity\common\enums\NiBaoEquityEnum;
  19. use addons\NiBaoEquity\common\models\NibaoEquityWallet;
  20. use addons\RedeemCard\common\service\UserService;
  21. use addons\Redpack\common\models\RedpackWallet;
  22. use addons\ScoreExpansion\common\models\ScoreExpansionWallet;
  23. use common\enums\AddonsEnum;
  24. use addons\Store\common\models\StoreCoupon;
  25. use addons\Store\common\models\StoreCouponUserRelate;
  26. use addons\WriteOff\common\models\WriteOffMember;
  27. use addons\BossWeightBonus\common\models\AddonsBossShares;
  28. use addons\PubMethod\common\enums\PubMethodEnums;
  29. use common\enums\DiyEnum;
  30. use common\enums\StatusEnum;
  31. use common\models\api\AccessToken;
  32. use common\models\base\BaseActiveRecord;
  33. use common\models\common\Addons;
  34. use common\models\common\BalanceLog;
  35. use common\models\mall\Mall;
  36. use common\models\mall\MallAddons;
  37. use PHPUnit\Util\Exception;
  38. use Yii;
  39. use yii\helpers\Json;
  40. /**
  41. * This is the model class for table "qimall_user_info".
  42. *
  43. *
  44. * @property int $id
  45. * @property int $mall_id 商城id
  46. * @property int $user_id
  47. * @property string $openid openid
  48. * @property string $unionid 用户所属平台的唯一标识
  49. * @property string $platform 平台名字:app:微信授权、wechat:公众号、mp-wx:小程序
  50. * @property string|null $platform_data 授权数据
  51. * @property int $status 状态[-1:删除;0:禁用;1启用]
  52. * @property int $created_at 创建时间
  53. * @property string $updated_at 更新时间
  54. */
  55. class UserInfo extends BaseActiveRecord
  56. {
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public static function tableName()
  61. {
  62. return '{{%user_info}}';
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function rules()
  68. {
  69. return [
  70. [['mall_id', 'user_id', 'status', 'created_at'], 'integer'],
  71. [['user_id'], 'required'],
  72. [['platform_data'], 'string'],
  73. [['openid'], 'string', 'max' => 64],
  74. [['unionid'], 'string', 'max' => 255],
  75. [['platform'], 'string', 'max' => 45],
  76. ];
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function attributeLabels()
  82. {
  83. return [
  84. 'id' => 'ID',
  85. 'mall_id' => '商城id',
  86. 'user_id' => 'User ID',
  87. 'openid' => 'openid',
  88. 'unionid' => '用户所属平台的唯一标识',
  89. 'platform' => '平台名字:app:微信授权、wechat:公众号、mp-wx:小程序',
  90. 'platform_data' => '授权数据',
  91. 'status' => '状态[-1:删除;0:禁用;1启用]',
  92. 'created_at' => '创建时间',
  93. 'updated_at' => '更新时间',
  94. ];
  95. }
  96. /**
  97. * 保存数据
  98. * @param array $params
  99. * @return bool|UserInfo
  100. */
  101. public static function setData(array $params)
  102. {
  103. try {
  104. $model = new self();
  105. $model->loadDefaultValues();
  106. $params['platform_data'] = json_encode($params['platform_data'] ?? [], JSON_NUMERIC_CHECK);
  107. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  108. return $model;
  109. } catch (Exception $e) {
  110. self::$static_error = $e->getMessage();
  111. return false;
  112. }
  113. }
  114. /**
  115. * 获取会员中心的用户资产
  116. * @Author: lun
  117. * @DateTime: 2021/11/15 0015 10:39
  118. * @Copyright: copyright (c) 2021 广东七件事集团
  119. * @param $mall_id
  120. * @param $user_id
  121. * @param $capital
  122. */
  123. public static function getCapital($mall_id, $user_id, $capital)
  124. {
  125. $capitalArr = Json::decode($capital, true);
  126. $wallet = UserWallet::getOne([['user_id' => $user_id]], true, [], false, 'score,balance,commission');
  127. $data = [];
  128. foreach ($capitalArr as $code) {
  129. $value = 0;
  130. switch ($code) {
  131. case 'balance':
  132. case 'score':
  133. //2023-04-18
  134. if($code == 'balance'){
  135. //判断是否有卡券插件
  136. if (MallAddons::isInstall($mall_id,AddonsEnum::ADDONS_NAME_CARD_COUPONS)) {
  137. $allMoney = CardCouponsScoreGive::find()
  138. ->where(['mall_id' => $mall_id, 'receive_user_id'=>$user_id,'is_active'=>CardCouponsScoreGive::ACTIVATED,'status'=>StatusEnum::ENABLED,'is_open'=>CardCouponsScoreGive::OPEN])
  139. ->andWhere(['<=','start_at',time()])
  140. ->andWhere(['>=','end_at',time()])
  141. ->sum('can_use_money');
  142. $wallet['balance'] = bcadd($wallet['balance'], $allMoney,2);
  143. }
  144. }
  145. //2023-04-18
  146. $value = $wallet[$code] ?: 0;
  147. $title = Yii::$app->services->setting->mall->get($mall_id, "{$code}.{$code}_name");
  148. $path[$code] = $code == 'balance' ? '/plugins/pages/assets/balance/index' : '/plugins/pages/assets/currency/index';
  149. break;
  150. case 'commission':
  151. $value = $wallet[$code] ?: 0;
  152. $title = '分红';
  153. $path[$code] = '/plugins/public/promotion/index';
  154. break;
  155. case 'coupon':
  156. $value = 0;
  157. $coupon_where = "acu.end_time > " . time() . " and acu.status = " . StatusEnum::ENABLED . " and acu.user_id = " . $user_id . " and acu.is_use = 0 and acu.giving_status <> 2 and acu.is_force_failure = 0";
  158. // $coupon_where .= " and ac.status=" . StatusEnum::ENABLED;
  159. $coupon_where .= " and acu.giving_status in (0,1) and acu.coupon_status not in (3, 4)"; // 过滤掉已失效和已过期优惠券
  160. if (MallAddons::isInstall($mall_id,'Coupon')) {
  161. $count = AddonsCouponUserRelate::find()
  162. ->alias("acu")
  163. // ->rightJoin(AddonsCoupon::tableName() . ' as ac', 'ac.id = acu.coupon_id')
  164. ->select('id')
  165. ->where($coupon_where)
  166. ->count();
  167. if($count) $value+=$count;
  168. }
  169. if(MallAddons::isInstall($mall_id,'Store')){
  170. $coupon_where = "acu.end_time > " . time() . " and acu.status = " . StatusEnum::ENABLED . " and acu.user_id = " . $user_id . " and acu.is_use = 0 and acu.giving_status <> 2 and acu.is_force_failure = 0";
  171. $coupon_where .= " and acu.giving_status in (0,1) and acu.coupon_status not in (3, 4)";
  172. $count = StoreCouponUserRelate::find()
  173. ->alias("acu")
  174. // ->rightJoin(StoreCoupon::tableName() . ' as ac', 'ac.id = acu.coupon_id')
  175. ->select('id')
  176. ->where($coupon_where)
  177. ->count();
  178. if($count) $value+=$count;
  179. }
  180. $title = '优惠券';
  181. $path[$code] = '/plugins/pages/coupon/index';
  182. break;
  183. case 'redpack':
  184. $redpack = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'Redpack', 'status' => StatusEnum::ENABLED]]);
  185. if ($redpack) {
  186. $value = 0;
  187. $redpack_wallet = RedpackWallet::getOne([['user_id' => $user_id, 'status' => StatusEnum::ENABLED]]);
  188. if ($redpack_wallet) {
  189. $value = bcadd($redpack_wallet['redpack'], $redpack_wallet['frozen_redpack'], 2);
  190. }
  191. }
  192. $redpack_name = Yii::$app->services->setting->addons->get($mall_id, 'Redpack', 'basic.redpack_name');
  193. $title = empty($redpack_name) ? '红包' : $redpack_name;
  194. $path[$code] = '/plugins/Redpack/redEnvelopes';
  195. break;
  196. case 'hi_bei':
  197. $higo = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'HiGo', 'status' => StatusEnum::ENABLED]]);
  198. if ($higo) {
  199. $value = 0;
  200. $higo_wallet = HigoWallet::getOne([['user_id' => $user_id]]);
  201. if ($higo_wallet) $value = bcmul($higo_wallet['hi_bei'], 1, 3);
  202. }
  203. $name = WalletLogic::getWalletTypeMsg($mall_id, 'hi_bei');
  204. $title = $name ?? '嗨贝';
  205. $path[$code] = '/plugins/HiGo/HiCurrency/index';
  206. break;
  207. case 'score-expansion':
  208. $scoreExpansion = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'ScoreExpansion', 'status' => StatusEnum::ENABLED]]);
  209. if ($scoreExpansion) {
  210. $value = 0;
  211. $scoreExpansionWallet = ScoreExpansionWallet::getOne([['user_id' => $user_id]]);
  212. if ($scoreExpansionWallet) {
  213. $value = bcadd($scoreExpansionWallet['integral'], $scoreExpansionWallet['frozen_integral'], 2);
  214. }
  215. }
  216. $scoreExpansionName = Yii::$app->services->setting->addons->get($mall_id, 'ScoreExpansion', 'basic.integral_name');
  217. $title = empty($scoreExpansionName) ? '积分拓客' : $scoreExpansionName;
  218. $path[$code] = '/plugins2/ScoreExpansion/redEnvelopes';
  219. break;
  220. case 'contribution-currency':
  221. $ContributionCurrency = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'ContributionCurrency', 'status' => StatusEnum::ENABLED]]);
  222. if ($ContributionCurrency) {
  223. $value = 0;
  224. $ContributionCurrencyWallet = ContributionWallet::getOne([['user_id' => $user_id]]);
  225. if ($ContributionCurrencyWallet) {
  226. $value = $ContributionCurrencyWallet['contribution_value'] ?: 0;
  227. }
  228. }
  229. $title = '贡献值';
  230. $path[$code] = '/plugins2/ContributionCurrency/index';
  231. break;
  232. case 'nibao':
  233. case 'nibao_score':
  234. $nibao = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'NiBao', 'status' => StatusEnum::ENABLED]]);
  235. if ($nibao) {
  236. $value = 0;
  237. $nibao_wallet = NibaoWallet::getUserWalletValue($mall_id, $user_id);
  238. if ($nibao_wallet) $value = bcmul($nibao_wallet[$code], 1, 3);
  239. }
  240. $text_arr = NiBaoEnum::getWalletText($mall_id);
  241. $title = $text_arr[$code];
  242. $path_arr = [
  243. 'nibao' => '/plugins2/NiBao/index',
  244. 'nibao_score' => '/plugins2/NiBaoAchievement/GreenIntegrateList'
  245. ];
  246. $path[$code] = $path_arr[$code];
  247. break;
  248. case 'equity':
  249. $nibao_equity = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'NiBaoEquity', 'status' => StatusEnum::ENABLED]]);
  250. if ($nibao_equity) {
  251. $value = 0;
  252. $nibao_equity_wallet = NibaoEquityWallet::getOne([['user_id' => $user_id]]);
  253. if ($nibao_equity_wallet) $value = $nibao_equity_wallet[$code];
  254. }
  255. $text_arr = NiBaoEquityEnum::getWalletText($mall_id);
  256. $title = $text_arr[$code];
  257. $path[$code] = '/plugins2/NiBaoEquity/EquityList';
  258. break;
  259. case 'energy_value':
  260. $energy_value = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'EnergyValue', 'status' => StatusEnum::ENABLED]]);
  261. if ($energy_value) {
  262. $energy_user_wallet_class = \addons\EnergyValue\common\services\WalletService::class;
  263. $value = $energy_user_wallet_class::getUserWallet($mall_id, $user_id);
  264. }
  265. $text_arr = EnergyValueEnum::getWalletText($mall_id);
  266. $title = $text_arr[$code];
  267. $path[$code] = '/plugins2/EnergyValue/index';
  268. break;
  269. case 'write_off':
  270. $WriteOff = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'WriteOff', 'status' => StatusEnum::ENABLED]]);
  271. if ($WriteOff) {
  272. $value = 0;
  273. $WriteOffMember = WriteOffMember::getOne([['user_id' => $user_id,'status' => StatusEnum::ENABLED]]);
  274. if ($WriteOffMember) {
  275. $value = $WriteOffMember['num'] ?: 0;
  276. }
  277. }
  278. $title = '核销码';
  279. $path[$code] = '/plugins3/WWriteOff/check_code';
  280. break;
  281. case 'digital':
  282. $user_digital = UserDigital::getOne([['mall_id' => $mall_id], ['user_id' => $user_id], ['status' => StatusEnum::ENABLED]], true, [], false, 'digital');
  283. $value = $user_digital[$code] ?: 0;
  284. $title = Yii::$app->services->setting->mall->get($mall_id, "{$code}.name");
  285. $path[$code] = '/plugins3/ContributionRelease/currency/list';
  286. break;
  287. case 'devote_redpack':
  288. $redpack = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'Devote', 'status' => StatusEnum::ENABLED]]);
  289. if ($redpack) {
  290. $value = 0;
  291. /** @var \addons\Devote\common\models\DevoteWallet $devote_wallet_class */
  292. $devote_wallet_class = \addons\Devote\common\models\DevoteWallet::class;
  293. $devote_wallet = $devote_wallet_class::getOne([['user_id' => $user_id]]);
  294. if ($devote_wallet) {
  295. $value = bcadd($devote_wallet['redpack'], $devote_wallet['frozen_redpack'], 2);
  296. }
  297. }
  298. $redpack_name = Yii::$app->services->setting->addons->get($mall_id, 'Devote', 'basic.redpack_name');
  299. $title = empty($redpack_name) ? '红包' : $redpack_name;
  300. $path[$code] = '/plugins3/ContributionRelease/currency/digitalList';
  301. break;
  302. case 'redeem_card':
  303. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_REDEEM_CARD)) {
  304. $service = new UserService();
  305. $value = $service->wallet($mall_id, $user_id);
  306. $title = $service->symbolName($mall_id);
  307. }
  308. $title = empty($title) ? '兑换卡' : $title;
  309. $path[$code] = "/plugins2/partnerDistributor/redemptionCard/redemptionCard";
  310. break;
  311. case 'boss_shares':
  312. $BossWeightBonus = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'BossWeightBonus', 'status' => StatusEnum::ENABLED]]);
  313. if ($BossWeightBonus) {
  314. $value = 0;
  315. $BossShares = AddonsBossShares::getOne([['user_id' => $user_id,'status' => StatusEnum::ENABLED]]);
  316. if ($BossShares) {
  317. $value = $BossShares['shares_num'] ?: 0;
  318. }
  319. }
  320. $title = '股指';
  321. $path[$code] = '/plugins3/BossWeightBonus/index';
  322. break;
  323. case 'dividend_value_reward': // 分红值
  324. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_DIVIDEND_VALUE_REWARD)) {
  325. $service = new \addons\DividendValueReward\common\service\UserService();
  326. $value = $service->wallet($mall_id, $user_id);
  327. $title = $service->symbolName($mall_id);
  328. }
  329. $title = empty($title) ? '分红值' : $title;
  330. $path[$code] = "/plugins4/DividendValueReward/index";
  331. break;
  332. case 'contribute_cy':
  333. case 'midou_cy':
  334. case 'gold_coin_cy':
  335. $title = '';
  336. $page = '';
  337. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_FUN_TOWN)) {
  338. $serv = new \addons\FunTown\common\services\BackendService();
  339. $value = $serv->getUserWallet($mall_id, $user_id, $code);
  340. $page_name = $serv->getWalletPageName($code);
  341. $title = $page_name['name'];
  342. $page = $page_name['page'];
  343. }
  344. $path[$code] = $page;
  345. break;
  346. case 'secondary_card':
  347. $title = '次卡';
  348. $path[$code] = DiyEnum::SECONDARY_CARD_LIST;
  349. if (MallAddons::isInstall($mall_id, 'SecondaryCard')) {
  350. $count = \addons\SecondaryCard\common\models\SecondaryCardOrder::find()->where(['user_id'=>$user_id,'order_status'=>0])
  351. ->andWhere(['>','open_time',0])
  352. ->count();
  353. if(!empty($count)) {
  354. $value = $count;
  355. }
  356. }
  357. break;
  358. case 'lvse': // 绿色积分
  359. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_LOVE_MALL)) {
  360. $service = new \addons\LoveMall\common\service\CommonService();
  361. $value = $service->get_capital_value('lvse',$mall_id, $user_id);
  362. $title = $service->get_capital_name('lvse',$mall_id);
  363. }
  364. $title = empty($title) ? '绿色积分' : $title;
  365. $path[$code] = "/plugins4/LoveMall/propertys?type=1";
  366. break;
  367. case 'shengtai': // 生态积分
  368. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_LOVE_MALL)) {
  369. $service = new \addons\LoveMall\common\service\CommonService();
  370. $value = $service->get_capital_value('shengtai',$mall_id, $user_id);
  371. $title = $service->get_capital_name('shengtai',$mall_id);
  372. }
  373. $title = empty($title) ? '生态积分' : $title;
  374. $path[$code] = "/plugins4/LoveMall/propertys?type=2";
  375. break;
  376. case 'gongxian': // 贡献值
  377. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_LOVE_MALL)) {
  378. $service = new \addons\LoveMall\common\service\CommonService();
  379. $value = $service->get_capital_value('gongxian',$mall_id, $user_id);
  380. $title = $service->get_capital_name('gongxian',$mall_id);
  381. }
  382. $title = empty($title) ? '贡献值' : $title;
  383. $path[$code] = "/plugins4/LoveMall/rights";
  384. break;
  385. case 'gongyi': // 公益基金
  386. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_LOVE_MALL)) {
  387. $service = new \addons\LoveMall\common\service\CommonService();
  388. $value = $service->get_capital_value('gongyi',$mall_id, $user_id);
  389. $title = $service->get_capital_name('gongyi',$mall_id);
  390. }
  391. $title = empty($title) ? '公益基金' : $title;
  392. $path[$code] = "/plugins4/LoveMall/propertys?type=5";
  393. break;
  394. case 'jintie': // 津贴券
  395. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_LOVE_MALL)) {
  396. $service = new \addons\LoveMall\common\service\CommonService();
  397. $value = $service->get_capital_value('jintie',$mall_id, $user_id);
  398. $title = $service->get_capital_name('jintie',$mall_id);
  399. }
  400. $title = empty($title) ? '津贴券' : $title;
  401. $path[$code] = "/plugins4/LoveMall/propertys?type=3";
  402. break;
  403. case 'tongzheng': // 通证积分
  404. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_LOVE_MALL)) {
  405. $service = new \addons\LoveMall\common\service\CommonService();
  406. $value = $service->get_capital_value('tongzheng',$mall_id, $user_id);
  407. $title = $service->get_capital_name('tongzheng',$mall_id);
  408. }
  409. $title = empty($title) ? '通证积分' : $title;
  410. $path[$code] = "/plugins4/LoveMall/rights";
  411. break;
  412. case 'tongzhengquan': // 通证券
  413. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_LOVE_MALL)) {
  414. $service = new \addons\LoveMall\common\service\CommonService();
  415. $value = $service->get_capital_value('tongzhengquan',$mall_id, $user_id);
  416. $title = $service->get_capital_name('tongzhengquan',$mall_id);
  417. }
  418. $title = empty($title) ? '通证券' : $title;
  419. $path[$code] = "/plugins4/LoveMall/propertys?type=4";
  420. break;
  421. case 'qiquan': // 期权股
  422. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_LOVE_MALL)) {
  423. $service = new \addons\LoveMall\common\service\CommonService();
  424. $value = $service->get_capital_value('qiquan',$mall_id, $user_id);
  425. $title = $service->get_capital_name('qiquan',$mall_id);
  426. }
  427. $title = empty($title) ? '期权股' : $title;
  428. $path[$code] = "/plugins4/LoveMall/propertys?type=6";
  429. break;
  430. case 'consumer_coupons':
  431. $consumer_coupons = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => 'ConsumerCoupons', 'status' => StatusEnum::ENABLED]]);
  432. if ($consumer_coupons) {
  433. $value = 0;
  434. $consumer_coupons_wallet = ConsumerCouponsWallet::getOne([['user_id' => $user_id]]);
  435. if ($consumer_coupons_wallet) {
  436. $value = bcadd($consumer_coupons_wallet['money'], $consumer_coupons_wallet['frozen_money'], 2);
  437. }
  438. }
  439. $consumer_coupons_name = Yii::$app->services->setting->addons->get($mall_id, 'ConsumerCoupons', 'basic.custom_name');
  440. $title = empty($consumer_coupons_name) ? '消费券' : $consumer_coupons_name;
  441. $path[$code] = '/plugins4/ConsumerCoupons/index';
  442. break;
  443. case 'drip': //分红池-酒滴
  444. case 'bottle'://分红池-酒权
  445. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_BONUS_POOL)) {
  446. $configs = \Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_BONUS_POOL, 'basic');
  447. if ($configs['is_enable'] == 1) {
  448. $bonus_pool_user_wallet = BonusPoolUserWallet::getOne([
  449. ['mall_id' => $mall_id],
  450. ['user_id' => $user_id],
  451. ['status' => StatusEnum::ENABLED]
  452. ], true);
  453. $drip_name = $configs['bottle_name'] ? $configs['bottle_name']: '酒滴';
  454. $bottle_name = $configs['bottle_other_name'] ? $configs['bottle_other_name']: '酒滴';
  455. $title = $code == 'drip' ? $drip_name : $bottle_name;
  456. $value = $code == 'drip' ? $bonus_pool_user_wallet['drip'] : $bonus_pool_user_wallet['bottle'];
  457. $path[$code] = $code == 'drip' ? '/customAddons/BonusPool/currency?type=drip' : '/customAddons/BonusPool/currency?type=bottle';
  458. }
  459. }
  460. break;
  461. case 'coin':
  462. $configs = \Yii::$app->services->setting->addons->get($mall_id, BottleCouponEnum::ADDONS_NAME, 'basic');
  463. $title = $configs['coin_name'] ? $configs['coin_name'] : '金币';
  464. if (MallAddons::isInstall($mall_id, 'BottleCoupon')) {
  465. $count = \addons\BottleCoupon\common\models\BottleCouponUserWallet::find()->where(['user_id'=>$user_id,'mall_id'=> $mall_id])
  466. ->one();
  467. if(!empty($count)) {
  468. $value = $count['coin'];
  469. }
  470. }
  471. $path[$code] = '/plugins/pages/assets/currency/index?home_type=coin';
  472. break;
  473. case 'bottle_coupon':
  474. $configs = \Yii::$app->services->setting->addons->get($mall_id, BottleCouponEnum::ADDONS_NAME, 'basic');
  475. $title = $configs['coupon_name'] ? $configs['coupon_name'] : '酒券';
  476. if (MallAddons::isInstall($mall_id, 'BottleCoupon')) {
  477. $count = \addons\BottleCoupon\common\models\BottleCouponUserWallet::find()->where(['user_id'=>$user_id,'mall_id'=> $mall_id])
  478. ->one();
  479. if(!empty($count)) {
  480. $value = $count['coupon'];
  481. }
  482. }
  483. $path[$code] = '/plugins/pages/assets/currency/index?home_type=bottle_coupon';
  484. break;
  485. case 'quota':
  486. $configs = \Yii::$app->services->setting->addons->get($mall_id, BottleCouponEnum::ADDONS_NAME, 'basic');
  487. $title = $configs['quota_name'] ? $configs['quota_name'] : '酒券奖励';
  488. if (MallAddons::isInstall($mall_id, 'BottleCoupon')) {
  489. $count = \addons\BottleCoupon\common\models\BottleCouponUserWallet::find()->where(['user_id'=>$user_id,'mall_id'=> $mall_id])
  490. ->one();
  491. if(!empty($count)) {
  492. $value = $count['quota'];
  493. }
  494. }
  495. $path[$code] = '/plugins/pages/assets/currency/index?home_type=quota';
  496. break;
  497. case 'huidian':
  498. $configs = \Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_HUI_DIAN, 'basic');
  499. $title = $configs['custom_name'] ?? '惠点';
  500. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_HUI_DIAN) && $configs['is_enable']) {
  501. $count = \addons\HuiDian\common\models\Huidian::find()->where(['user_id'=>$user_id, 'mall_id'=> $mall_id])
  502. ->one();
  503. if(!empty($count)) {
  504. $value = $count['amount'];
  505. }
  506. }
  507. $path[$code] = '/customAddons/HuiDianAssets/index';
  508. break;
  509. case 'gold_bean':
  510. $configs = \Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_GOLD_BEAN, 'basic');
  511. $title = $configs['custom_name'] ?? '金豆';
  512. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_GOLD_BEAN) && $configs['is_enable']) {
  513. $count = \addons\GoldBean\common\models\GoldBean::find()->where(['user_id'=>$user_id, 'mall_id'=> $mall_id])
  514. ->one();
  515. if(!empty($count)) {
  516. $value = $count['frozen_amount'];
  517. }
  518. }
  519. $path[$code] = '/customAddons/GoldBean/index';
  520. break;
  521. case 'cost_score':
  522. case 'gold_score':
  523. case 'partner_score':
  524. case 'consumer_card':
  525. case 'score_secondary_card':
  526. case 'shop_score':
  527. $title = '';
  528. $page = '';
  529. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_SCORE_GAME)) {
  530. $serv = new \addons\ScoreGame\common\logic\UserLogic();
  531. $user_wallet = $serv->getUserWallet($mall_id, $user_id, $code);
  532. if(!$user_wallet['is_show']) break;
  533. $value = $user_wallet['num'];
  534. $title = $user_wallet['name'];
  535. $page = $user_wallet['page'];
  536. }
  537. $path[$code] = $page;
  538. break;
  539. case 'zhaike_score': //宅客体脂秤-门店积分
  540. $title = '门店积分';
  541. if (MallAddons::isInstall($mall_id, 'ZhaiKe')) {
  542. $count = \addons\ZhaiKe\common\models\ZhaiKeUserWallet::find()->where(['user_id'=>$user_id,'mall_id'=> $mall_id])
  543. ->select('id,user_id,sum(score) as total_score')->groupBy('user_id')->all();
  544. if(!empty($count)) {
  545. $value = $count[0]['total_score'];
  546. }
  547. }
  548. $path[$code] = '/customAddons/BodyFatScale/store-score/index';
  549. break;
  550. case 'grain_num':
  551. $configs = \Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_PUB_METHOD, 'basic');
  552. $title = $configs['grain_name'] ? $configs['grain_name'] : '酒粮';
  553. if (MallAddons::isInstall($mall_id, 'PubMethod')) {
  554. $count = \addons\PubMethod\common\models\PubMethodUser::find()->where(['user_id' => $user_id, 'mall_id' => $mall_id])
  555. ->one();
  556. if(!empty($count)) {
  557. $value = $count['grain_num'];
  558. }
  559. }
  560. $path[$code] = '/customAddons2/PubMethod/pubMethodDetails';
  561. break;
  562. case 'drinks_num':
  563. $configs = \Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_PUB_METHOD, 'basic');
  564. $title = $configs['drinks_name'] ? $configs['drinks_name'] : '酒水';
  565. if (MallAddons::isInstall($mall_id, 'PubMethod')) {
  566. $count = \addons\PubMethod\common\models\PubMethodUser::find()->where(['user_id' => $user_id, 'mall_id' => $mall_id])
  567. ->one();
  568. if(!empty($count)) {
  569. $value = $count['drinks_num'];
  570. }
  571. }
  572. $path[$code] = '/customAddons2/PubMethod/pubMethodDetails';
  573. break;
  574. case 'frozen-perk-asset':
  575. $FrozenPerkAsset = MallAddons::getOne([['mall_id' => $mall_id, 'addons_name' => AddonsEnum::ADDONS_NAME_FROZEN_PERK_ASSET, 'status' => StatusEnum::ENABLED]]);
  576. if ($FrozenPerkAsset) {
  577. $value = 0;
  578. $AssetWallet = FrozenPerkAsset::getOne([['user_id' => $user_id],['mall_id' => $mall_id],['status' => StatusEnum::ENABLED]]);
  579. if ($AssetWallet) {
  580. $value = $AssetWallet['frozen_money'];
  581. }
  582. }
  583. $AssetName = Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_FROZEN_PERK_ASSET, 'basic.asset_name');
  584. $title = empty($AssetName) ? '冻结补贴' : $AssetName;
  585. $path[$code] = '/customAddons2/FrozenPerkAsset/index';
  586. break;
  587. }
  588. if(isset($path[$code])){
  589. $data[] = ['code' => $code, 'route' => $path[$code], 'title' => $title, 'value' => empty($value) ? 0 : $value];
  590. }
  591. }
  592. return $data;
  593. }
  594. public static function getExtraCapital($user_id, $data){
  595. $commission = 0;
  596. $func = function ($user_id){
  597. $wallet = UserWallet::getOne([['user_id' => $user_id]], true, [], false, 'commission');
  598. return $wallet['commission'] ?? 0;
  599. };
  600. if(isset($data['capital']) && !empty($data['capital'])) {
  601. $tmp_capital = array_column($data['capital'], 'value', 'code');
  602. if(isset($tmp_capital['commission'])){
  603. $commission = $tmp_capital['commission'];
  604. }else{
  605. $commission = $func($user_id);
  606. }
  607. }else{
  608. $commission = $func($user_id);;
  609. }
  610. return compact('commission');
  611. }
  612. public static function getExtraLevel($mall_id,$user_id, $code){
  613. $data = [];
  614. if (MallAddons::isInstall($mall_id, $code) == 0) return $data;
  615. switch ($code) {
  616. case AddonsEnum::ADDONS_NAME_AGENT:
  617. $agent = Agent::getOne([['user_id' => $user_id], ['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]], true, ['agentLevel']);
  618. $data['level_name'] = $agent['agentLevel']['name'] ?? '默认等级';
  619. $data['level'] = $agent['agentLevel']['level'];
  620. break;
  621. case AddonsEnum::ADDONS_NAME_AGENT_BASE:
  622. $agent = AgentBase::getOne([['user_id' => $user_id], ['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]], true, ['agentLevel']);
  623. $data['level_name'] = $agent['agentLevel']['name'] ?? '默认等级';
  624. $data['level'] = $agent['agentLevel']['level'];
  625. break;
  626. }
  627. return $data;
  628. }
  629. /**
  630. * 清除用户公众号及小程序授权
  631. *
  632. * @param $mallId
  633. * @param $userId
  634. * @param $platform
  635. *
  636. * @return void
  637. */
  638. public static function clearAuth($mallId, $userId = 0, $platform = '')
  639. {
  640. $where = ['mall_id' => $mallId];
  641. if (!$platform) {
  642. $where['platform'] = ['mp-wx', 'wechat'];
  643. } else {
  644. $where['platform'] = $platform;
  645. }
  646. if ($userId) {
  647. $where['user_id'] = $userId;
  648. }
  649. self::updateAll(['status' => -1], $where);
  650. // 清除登录授权信息
  651. $where['status'] = -1;
  652. $user_ids = self::find()->select('user_id')->where($where)->column();
  653. while (count($user_ids) > 0) {
  654. $user_id = array_shift($user_ids);
  655. $token = AccessToken::findOne(['user_id' => $user_id]);
  656. if (!empty($token)) {
  657. \Yii::$app->services->apiAccessToken->disableByAccessToken($token->access_token);
  658. }
  659. }
  660. }
  661. }