UserController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <?php
  2. namespace addons\HiGo\api\modules\v1\controllers;
  3. use addons\HiGo\common\enums\HiGoEnum;
  4. use addons\HiGo\common\logic\HiBeiLogic;
  5. use addons\HiGo\common\logic\RewardLogic;
  6. use addons\HiGo\common\models\HigoWallet;
  7. use addons\HiGo\common\models\HigoWalletFreezeLog;
  8. use addons\HiGo\common\models\HigoWalletLog;
  9. use addons\Mch\common\models\Mch;
  10. use addons\Store\common\models\Store;
  11. use Yii;
  12. use api\controllers\OnAuthController;
  13. use common\enums\AddonsEnum;
  14. use common\enums\StatusEnum;
  15. use common\helpers\ApiCode;
  16. use common\models\mall\MallAddons;
  17. use common\models\order\Order;
  18. /**
  19. *
  20. *
  21. * Class UserController
  22. * @package addons\HiGo\api\modules\v1\controllers
  23. */
  24. class UserController extends OnAuthController
  25. {
  26. public $modelClass = '';
  27. /**
  28. * 不用进行登录验证的方法
  29. *
  30. * 例如: ['index', 'update', 'create', 'view', 'delete']
  31. * 默认全部需要验证
  32. *
  33. * @var array
  34. */
  35. protected $authOptional = [];
  36. /**
  37. * @Description: 会员/商户嗨贝概况
  38. * @Author: qi
  39. * @DateTime 2022-11-16 16:41:36
  40. * @return mixed
  41. */
  42. public function actionUserCenter()
  43. {
  44. if (!Yii::$app->request->isGet) {
  45. return $this->error('请求方式非法');
  46. }
  47. $params = Yii::$app->request->get();
  48. $res = Yii::$app->services->validate->validate($params, [
  49. [['type'], 'required'],
  50. ['type', 'in', 'range' => [1, 2]], //1-普通会员,2-商家
  51. ]);
  52. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  53. $higo_wallet = HigoWallet::getOne([['mall_id' => $this->mall_id], ['user_id' => $this->user_id], ['status' => StatusEnum::ENABLED]], true);
  54. $basic = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'basic');
  55. $protocol = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'protocol');
  56. $airdrop_income = HigoWalletLog::find()
  57. ->where([
  58. 'and', ['mall_id' => $this->mall_id], ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI], ['status' => StatusEnum::ENABLED], ['user_id' => $this->user_id], ['from_type' => HiGoEnum::FROM_TYPE_AIRDROP]
  59. ])->sum('change_num');
  60. $consumption_income = HigoWalletLog::find()
  61. ->where([
  62. 'and', ['mall_id' => $this->mall_id], ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI], ['status' => StatusEnum::ENABLED], ['user_id' => $this->user_id], ['from_type' => HiGoEnum::FROM_TYPE_ORDER_GOODS]
  63. ])->sum('change_num');
  64. $cumulative_income = HigoWalletLog::find()
  65. ->where([
  66. 'and', ['mall_id' => $this->mall_id], ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI], ['status' => StatusEnum::ENABLED], ['user_id' => $this->user_id], ['change_type' => 'add']
  67. ])->sum('change_num');
  68. $value_cumulative_income = HigoWalletLog::find()
  69. ->where([
  70. 'and', ['mall_id' => $this->mall_id], ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_VALUE], ['status' => StatusEnum::ENABLED], ['user_id' => $this->user_id], ['change_type' => 'add']
  71. ])->andWhere(['!=','from_type',HiGoEnum::FROM_TYPE_REPURCHASE_ACTIVE])->sum('change_num');
  72. $today_earnings = HigoWalletLog::find()
  73. ->where([
  74. 'and', ['mall_id' => $this->mall_id], ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI], ['status' => StatusEnum::ENABLED], ['user_id' => $this->user_id], ['change_type' => 'add'],
  75. ['>=', 'created_at', strtotime(date('Y-m-d'))], ['<=', 'created_at', strtotime(date('Y-m-d 23:59:59'))]
  76. ])->sum('change_num');
  77. $recharge = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'recharge');
  78. $withdraw = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'withdraw');
  79. $cash_status = $withdraw['cash_status'] ? json_decode($withdraw['cash_status'], true) : 0;
  80. $cash_status = is_array($cash_status) ? ($cash_status['value'] ?? 0) : $cash_status;
  81. //嗨呗现在价值
  82. $now_price = HiBeiLogic::getNowPrice($this->mall_id);
  83. $data = [
  84. 'hi_bei' => $higo_wallet['hi_bei'] ?? 0,
  85. 'hi_bei_name' => $basic['hi_bei_name'] ?? '嗨贝',
  86. 'hi_value' => $higo_wallet['hi_value'] ?? 0,
  87. 'hi_value_name' => $basic['hi_value_name'] ?? '嗨值',
  88. 'airdrop_income' => $airdrop_income ?? 0, //空投收益
  89. 'cumulative_income' => $cumulative_income ?? 0, //累计收益
  90. 'today_earnings' => $today_earnings ?? 0, //今日收益
  91. 'value_cumulative_income' => $value_cumulative_income ?? 0, //嗨值累计收益
  92. 'consumption_income' => $consumption_income ?? 0, //消费收益
  93. 'nav_text' => $basic['hi_bei_name'] ?? '嗨贝',
  94. 'member_notice' => $protocol['member_notice'] ?? '',
  95. 'enable_recharge' => $recharge['enable'] ?? 0,
  96. 'enable_withdraw' => $cash_status,
  97. 'freeze_hi_bei' => $higo_wallet['freeze_hi_bei'] ?? 0,
  98. 'freeze_hi_value' => $higo_wallet['freeze_hi_value'] ?? 0,
  99. 'enable_transfer' => $basic['hi_bei_transfer_enable'] ?? 0,
  100. 'hi_bei_now_price' => $now_price
  101. ];
  102. $is_mch = 0;
  103. if ($params['type'] == 2) {
  104. $data['reward_details'] = '0.00';
  105. $data['reward_hi_bei'] = '0.00';
  106. if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE)) {
  107. $store = Store::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]);
  108. if ($store) $is_mch = 1;
  109. }
  110. if ($is_mch == 0 && MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_MCH)) {
  111. $mch = Mch::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]);
  112. if ($mch) $is_mch = 1;
  113. }
  114. }
  115. $data['is_mch'] = $is_mch;
  116. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $data);
  117. }
  118. /**
  119. * @Description: 会员/商户嗨贝明细
  120. * @Author: qi
  121. * @DateTime 2022-11-16 16:40:18
  122. * @return mixed
  123. */
  124. public function actionUserLog()
  125. {
  126. if (!Yii::$app->request->isGet) {
  127. return $this->error('请求方式非法');
  128. }
  129. $params = Yii::$app->request->get();
  130. $res = Yii::$app->services->validate->validate($params, [
  131. [['type'], 'required'],
  132. ['type', 'in', 'range' => [1, 2]],
  133. ['page', 'integer']
  134. ]);
  135. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  136. $param = [
  137. 'where' => [
  138. ['mall_id' => $this->mall_id],
  139. ['user_id' => $this->user_id],
  140. ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI],
  141. ['>=', 'status', 1]
  142. ],
  143. 'select' => 'id,change_type,change_num,after_num,desc,created_at,from_type',
  144. 'page' => $params['page'] ?? 1,
  145. 'order' => 'id DESC'
  146. ];
  147. $list = HigoWalletLog::listPage($param);
  148. if ($list === false) {
  149. return $this->error(HigoWalletLog::getStaticError());
  150. }
  151. $from_type_map = HiGoEnum::getFromTypeMap($this->mall_id);
  152. foreach ($list['list'] as &$item) {
  153. $item['from_type_text'] = $from_type_map[$item['from_type']] ?? '';
  154. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  155. }
  156. unset($item);
  157. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $list);
  158. }
  159. /**
  160. * @Description: 会员/商户嗨贝记录
  161. * @Author: qi
  162. * @DateTime 2022-11-16 16:40:18
  163. * @return mixed
  164. */
  165. public function actionHiBeiLog()
  166. {
  167. if (!Yii::$app->request->isGet) {
  168. return $this->error('请求方式非法');
  169. }
  170. $params = Yii::$app->request->get();
  171. $res = Yii::$app->services->validate->validate($params, [
  172. [['type', 'from'], 'required'],
  173. ['type', 'in', 'range' => [1, 2]],
  174. ['page', 'integer'],
  175. ['from', 'in', 'range' => [1, 2]]
  176. ]);
  177. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  178. $where = [];
  179. switch ($params['from']) {
  180. case 1: //空投收益
  181. $where = [['from_type' => HiGoEnum::FROM_TYPE_AIRDROP]];
  182. break;
  183. case 2: //今日收益
  184. $where = [
  185. ['>=', 'created_at', strtotime(date('Y-m-d 00:00:00'))],
  186. ['<=', 'created_at', strtotime(date('Y-m-d 23:59:59'))],
  187. ];
  188. break;
  189. default:
  190. break;
  191. }
  192. $param = [
  193. 'where' => array_merge([
  194. ['mall_id' => $this->mall_id],
  195. ['user_id' => $this->user_id],
  196. ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI],
  197. ['>=', 'status', 1],
  198. ], $where),
  199. 'select' => 'id,change_type,change_num,after_num,desc,created_at,from_type',
  200. 'page' => $params['page'] ?? 1,
  201. 'order' => 'id DESC'
  202. ];
  203. $list = HigoWalletLog::listPage($param);
  204. if ($list === false) {
  205. return $this->error(HigoWalletLog::getStaticError());
  206. }
  207. $from_type_map = HiGoEnum::getFromTypeMap($this->mall_id);
  208. $wallet_text = HiGoEnum::getHigoWalletText($this->mall_id);
  209. foreach ($list['list'] as &$item) {
  210. $item['from_type_text'] = $from_type_map[$item['from_type']] ?? '';
  211. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  212. $item['desc'] = str_replace('嗨贝',$wallet_text[HiGoEnum::WALLET_TYPE_HI_BEI],$item['desc']);
  213. }
  214. unset($item);
  215. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $list);
  216. }
  217. /**
  218. * @Description: 会员/商户嗨贝记录
  219. * @Author: qi
  220. * @DateTime 2022-11-16 16:40:18
  221. * @return mixed
  222. */
  223. public function actionTotalHiBeiLog()
  224. {
  225. if (!Yii::$app->request->isGet) {
  226. return $this->error('请求方式非法');
  227. }
  228. $params = Yii::$app->request->get();
  229. $res = Yii::$app->services->validate->validate($params, [
  230. [['date'], 'string'],
  231. ['page', 'integer'],
  232. ]);
  233. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  234. if (isset($params['date'])) {
  235. $year = substr($params['date'], 0, 4);
  236. $month = substr($params['date'], 5);
  237. } else {
  238. $year = date('Y');
  239. $month = date('m');
  240. }
  241. $day = date('t', strtotime($year . '-' . $month));
  242. $param = [
  243. 'where' => [
  244. ['mall_id' => $this->mall_id],
  245. ['user_id' => $this->user_id],
  246. ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI],
  247. ['>=', 'status', 1],
  248. ['>=', 'created_at', strtotime($year . '-' . $month)],
  249. ['<=', 'created_at', mktime(23, 59, 59, $month, $day, $year)]
  250. ],
  251. 'select' => 'id,change_type,change_num,after_num,desc,created_at,from_type',
  252. 'page' => $params['page'] ?? 1,
  253. ];
  254. $list = HigoWalletLog::listPage($param);
  255. if ($list === false) {
  256. return $this->error(HigoWalletLog::getStaticError());
  257. }
  258. $where = $param['where'];
  259. $where[] = ['change_type' => 'add'];
  260. $where[0] = 'and';
  261. $total_profit = HigoWalletLog::find()->where($where)->sum('change_num');
  262. $total_profit = $total_profit ?? 0;
  263. $from_type_map = HiGoEnum::getFromTypeMap($this->mall_id);
  264. $wallet_text = HiGoEnum::getHigoWalletText($this->mall_id);
  265. foreach ($list['list'] as &$item) {
  266. $item['from_type_text'] = $from_type_map[$item['from_type']] ?? '';
  267. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  268. $item['desc'] = str_replace('嗨贝',$wallet_text[HiGoEnum::WALLET_TYPE_HI_BEI],$item['desc']);
  269. }
  270. unset($item);
  271. $list['total_profit'] = $total_profit;
  272. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $list);
  273. }
  274. /**
  275. * @Description: 会员/商户嗨值记录
  276. * @Author: qi
  277. * @DateTime 2022-11-16 16:40:18
  278. * @return mixed
  279. */
  280. public function actionHiValueLog()
  281. {
  282. if (!Yii::$app->request->isGet) {
  283. return $this->error('请求方式非法');
  284. }
  285. $params = Yii::$app->request->get();
  286. $res = Yii::$app->services->validate->validate($params, [
  287. [['type', 'from'], 'required'],
  288. ['type', 'in', 'range' => [1, 2]],
  289. ['page', 'integer'],
  290. ['from', 'in', 'range' => [0, 1, 2]]
  291. ]);
  292. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  293. $where = [];
  294. switch ($params['from']) {
  295. case 0: //累计收益
  296. break;
  297. case 1: //消费收益
  298. $where = [['from_type' => HiGoEnum::FROM_TYPE_ORDER_GOODS]];
  299. break;
  300. case 2: //今日收益
  301. $where = [
  302. ['>=', 'created_at', strtotime(date('Y-m-d 00:00:00'))],
  303. ['<=', 'created_at', strtotime(date('Y-m-d 23:59:59'))],
  304. ];
  305. break;
  306. default:
  307. break;
  308. }
  309. $param = [
  310. 'where' => array_merge([
  311. ['mall_id' => $this->mall_id],
  312. ['user_id' => $this->user_id],
  313. ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_VALUE],
  314. ['>=', 'status', 1],
  315. ], $where),
  316. 'select' => 'id,change_type,change_num,after_num,desc,created_at,from_type',
  317. 'page' => $params['page'] ?? 1,
  318. 'order' => 'id desc'
  319. ];
  320. $list = HigoWalletLog::listPage($param);
  321. if ($list === false) {
  322. return $this->error(HigoWalletLog::getStaticError());
  323. }
  324. $from_type_map = HiGoEnum::getFromTypeMap($this->mall_id);
  325. $wallet_text = HiGoEnum::getHigoWalletText($this->mall_id);
  326. foreach ($list['list'] as &$item) {
  327. $item['from_type_text'] = $from_type_map[$item['from_type']] ?? '';
  328. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  329. $item['desc'] = str_replace('嗨值',$wallet_text[HiGoEnum::WALLET_TYPE_HI_VALUE],$item['desc']);
  330. }
  331. unset($item);
  332. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $list);
  333. }
  334. /**
  335. * @Description: 商家打赏: 展示
  336. * @Author: qi
  337. * @DateTime 2022-11-18 16:43:10
  338. * @return mixed
  339. */
  340. public function actionMchRewardShow()
  341. {
  342. if (!Yii::$app->request->isGet) {
  343. return $this->error('请求方式非法');
  344. }
  345. if (!$this->checkIsMch()) return $this->error('请求非法');
  346. $higo_wallet = HigoWallet::getOne([['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]], true);
  347. $basic = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'basic');
  348. $protocol = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'protocol');
  349. $data = [
  350. 'reward_rules' => $protocol['reward_rules'] ?? '',
  351. 'merchant_profit_multiple' => $basic['merchant_profit_multiple'] ?? 0,
  352. 'hi_bei' => $higo_wallet['hi_bei'] ?? 0,
  353. 'hi_bei_name' => $basic['hi_bei_name'] ?? '嗨贝',
  354. 'hi_value' => $higo_wallet['hi_value'] ?? 0,
  355. 'hi_value_name' => $basic['hi_value_name'] ?? '嗨值',
  356. ];
  357. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $data);
  358. }
  359. /**
  360. * @Description: 商家打赏:输入订单号验证
  361. * @Author: qi
  362. * @DateTime 2022-11-18 16:43:10
  363. * @return mixed
  364. */
  365. public function actionMchRewardCheck()
  366. {
  367. if (!Yii::$app->request->isPost) {
  368. return $this->error('请求方式非法');
  369. }
  370. $mch = $this->checkIsMch();
  371. if (!$mch) return $this->error('请求非法');
  372. $params = Yii::$app->request->post();
  373. $res = Yii::$app->services->validate->validate($params, [
  374. [['order_no'], 'required'],
  375. ]);
  376. //这里会传type = 2 ? 什么时候等于1【门店,多商户都是 2】
  377. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  378. // to do
  379. $basic = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'basic');
  380. if ($basic['mode_reward_method']) return $this->error('不支持商家打赏');
  381. $reward = RewardLogic::getOrderMerchantReward($params['order_no'], $mch);
  382. if (!$reward) return $this->error(RewardLogic::getStaticError());
  383. $data = [
  384. 'available_hi_bei' => $reward['hi_bei'],
  385. 'available_hi_value' => $reward['hi_value'],
  386. 'amount_consumption' => $reward['pay_money'],
  387. 'order_no' => $params['order_no'],
  388. ];
  389. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $data);
  390. }
  391. /**
  392. * @Description: 商家打赏
  393. * @Author: qi
  394. * @DateTime 2022-11-18 16:43:10
  395. * @return mixed
  396. */
  397. public function actionMchReward()
  398. {
  399. if (!Yii::$app->request->isPost) {
  400. return $this->error('请求方式非法');
  401. }
  402. $mch = $this->checkIsMch();
  403. if (!$mch) return $this->error('请求非法');
  404. $params = Yii::$app->request->post();
  405. $res = Yii::$app->services->validate->validate($params, [
  406. [['order_no'], 'required'],
  407. ]);
  408. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  409. $basic = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'basic');
  410. if ($basic['mode_reward_method']) return $this->error('不支持商家打赏');
  411. $order = [];
  412. $mch_id = 0;
  413. $mch_name = '';
  414. if(isset($mch['store'])){
  415. $mch_id = $mch['store']['mch_id'];
  416. $mch_name = $mch['store']['mch_name'];
  417. $order = Order::findOne(['order_no' => $params['order_no'],'store_id' => $mch_id,'pay_status' => 1,'status' => StatusEnum::ENABLED]);
  418. }
  419. if(!$order && isset($mch['mch'])){
  420. $mch_id = $mch['mch']['mch_id'];
  421. $mch_name = $mch['mch']['mch_name'];
  422. $order = Order::findOne(['order_no' => $params['order_no'],'mch_id' => $mch_id,'pay_status' => 1,'status' => StatusEnum::ENABLED]);
  423. }
  424. if(!$order) return $this->error('订单不存在');
  425. $res = RewardLogic::doMerchantReward($params['order_no'], $mch_id, $this->user_id, $mch_name);
  426. if (!$res) return $this->error(RewardLogic::getStaticError());
  427. return $this->success('打赏成功');
  428. }
  429. /**
  430. * @Description: 打赏记录
  431. * @Author: qi
  432. * @DateTime 2022-11-18 17:23:58
  433. * @return mixed
  434. */
  435. public function actionMchRewardList()
  436. {
  437. if (!Yii::$app->request->isGet) {
  438. return $this->error('请求方式非法');
  439. }
  440. $params = Yii::$app->request->get();
  441. $res = Yii::$app->services->validate->validate($params, [
  442. [['wallet_type'], 'required'],
  443. [['page'], 'integer'],
  444. ['wallet_type', 'in', 'range' => [HiGoEnum::WALLET_TYPE_HI_VALUE, HiGoEnum::WALLET_TYPE_HI_BEI]],
  445. ]);
  446. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  447. $param = [
  448. 'where' => [
  449. ['mall_id' => $this->mall_id],
  450. ['user_id' => $this->user_id],
  451. ['wallet_type' => $params['wallet_type']],
  452. ['from_type' => HiGoEnum::FROM_TYPE_MERCHANT_REWARD],
  453. ['>=', 'status', 1],
  454. ],
  455. 'select' => 'id,change_type,change_num,after_num,desc,created_at,source_table_id',
  456. 'page' => $params['page'] ?? 1,
  457. ];
  458. $list = HigoWalletLog::listPage($param);
  459. if ($list === false) {
  460. return $this->error(HigoWalletLog::getStaticError());
  461. }
  462. $basic = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'basic');
  463. $name = $basic[$params['wallet_type'] . '_name'] ?? ($params['wallet_type'] == HiGoEnum::WALLET_TYPE_HI_VALUE ? '嗨值' : '嗨贝');
  464. $souce_ids = array_column($list['list'], 'source_table_id');
  465. $order_list = Order::lists([
  466. 'where' => [['id' => $souce_ids], ['mall_id' => $this->mall_id]],
  467. 'with' => [
  468. 'detail' => function ($query) {
  469. $query->select('id, goods_id, order_id, goods_name, price, pic_url');
  470. }
  471. ],
  472. 'select' => 'id, mall_id, order_no',
  473. 'index' => 'id'
  474. ], true);
  475. foreach ($list['list'] as &$item) {
  476. $item['order_no'] = isset($order_list[$item['source_table_id']]) ? $order_list[$item['source_table_id']]['order_no'] : '';
  477. $item['pic_url'] = isset($order_list[$item['source_table_id']]) ? $order_list[$item['source_table_id']]['detail'][0]['pic_url'] : '';
  478. $item['price'] = isset($order_list[$item['source_table_id']]) ? $order_list[$item['source_table_id']]['detail'][0]['price'] : '';
  479. $item['goods_name'] = isset($order_list[$item['source_table_id']]) ? $order_list[$item['source_table_id']]['detail'][0]['goods_name'] : '';
  480. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  481. $item['reward_method'] = $name;
  482. }
  483. unset($item);
  484. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $list);
  485. }
  486. /**
  487. * 检测是否商家身份
  488. */
  489. private function checkIsMch()
  490. {
  491. $mch_list = [];
  492. $mch_info = [];
  493. if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE)) {
  494. $store = Store::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]);
  495. if ($store) {
  496. $mch_info['mch_id'] = $store['id'];
  497. $mch_info['mch_name'] = $store['store_name'];
  498. $mch_list['store'] = $mch_info;
  499. }
  500. }
  501. if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_MCH)) {
  502. $mch = Mch::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]);
  503. if ($mch) {
  504. $mch_info['mch_id'] = $mch['id'];
  505. $mch_info['mch_name'] = $mch['store_name'];
  506. $mch_list['mch'] = $mch_info;
  507. }
  508. }
  509. // return $mch_info;
  510. return $mch_list;
  511. }
  512. /**
  513. * @Description: 会员/商户嗨值冻结记录
  514. * @Author: qi
  515. * @DateTime 2022-12-01 14:42:18
  516. * @return mixed
  517. */
  518. public function actionHiValueFreezeLog()
  519. {
  520. if (!Yii::$app->request->isGet) {
  521. return $this->error('请求方式非法');
  522. }
  523. $params = Yii::$app->request->get();
  524. $res = Yii::$app->services->validate->validate($params, [
  525. // [['type', 'from'], 'required'],
  526. // ['type', 'in', 'range' => [1, 2]],
  527. ['page', 'integer'],
  528. // ['from', 'in', 'range' => [0, 1, 2]]
  529. ]);
  530. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  531. $where = [];
  532. $param = [
  533. 'where' => array_merge([
  534. ['mall_id' => $this->mall_id],
  535. ['user_id' => $this->user_id],
  536. ['wallet_type' => HiGoEnum::WALLET_TYPE_HI_VALUE],
  537. ['>=', 'status', 0],
  538. ], $where),
  539. 'select' => 'id,change_type,change_num,after_num,desc,created_at,from_type,status',
  540. 'page' => $params['page'] ?? 1,
  541. ];
  542. $list = HigoWalletFreezeLog::listPage($param);
  543. if ($list === false) {
  544. return $this->error(HigoWalletLog::getStaticError());
  545. }
  546. $from_type_map = HiGoEnum::getFreezeFromTypeMap();
  547. foreach ($list['list'] as &$item) {
  548. $item['from_type_text'] = $from_type_map[$item['from_type']] ?? '';
  549. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  550. $item['status_msg'] = $item['status'] > 0 ? '已解冻' : '冻结中';
  551. }
  552. unset($item);
  553. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $list);
  554. }
  555. /**
  556. * 模糊查询商家订单号
  557. * @return mixed|void
  558. */
  559. public function actionMchSearchOrder()
  560. {
  561. if (!Yii::$app->request->isPost) {
  562. return $this->error('请求方式非法');
  563. }
  564. $mch = $this->checkIsMch();
  565. if (!$mch) return $this->error('请求非法');
  566. $param = Yii::$app->request->post();
  567. $res = Yii::$app->services->validate->validate($param, [
  568. [['order_no'], 'required'],
  569. [['order_no'], 'string'],
  570. ]);
  571. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  572. $params[] = ['like', 'order_no', $param['order_no']];
  573. $params[] = ['=', 'mall_id', $this->mall_id];
  574. $params[] = ['=', 'pay_status', 1];
  575. $params[] = ['=', 'status', StatusEnum::ENABLED];
  576. $store_id = isset($mch['store']) ? $mch['store']['mch_id'] : 0;
  577. $mch_id = isset($mch['mch']) ? $mch['mch']['mch_id'] : 0;
  578. if($store_id > 0 && $mch_id > 0 ){
  579. $params[] = ['or', ['=', 'store_id', $store_id], ['=', 'mch_id', $mch_id]];
  580. }else{
  581. $params[] = ['and', ['=', 'store_id', $store_id], ['=', 'mch_id', $mch_id]];
  582. }
  583. $params = [
  584. 'select' => 'id,order_no,user_id',
  585. 'where' => $params,
  586. 'order' => 'id desc',
  587. 'page' => 1,
  588. 'limit' => 10,
  589. ];
  590. $list = Order::listPage($params, false, true);
  591. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $list);
  592. }
  593. }