FinanceController.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. <?php
  2. namespace backend\modules\mall\controllers;
  3. use backend\controllers\MallController;
  4. use backend\modules\mall\services\WithdrawalService;
  5. use common\enums\AddonsEnum;
  6. use common\enums\UserWalletEnum;
  7. use common\enums\WithdrawWayEnum;
  8. use common\globals\GlobalInvoke;
  9. use common\logic\common\AddonsLimit;
  10. use common\models\backend\Admin;
  11. use common\models\census\CensusMall;
  12. use common\models\census\CensusMallCapital;
  13. use common\models\census\CensusMallCapitalStatistics;
  14. use common\models\census\CensusMallPaymentSingleMonth;
  15. use common\models\census\CensusMallSingleMonth;
  16. use common\models\common\CapitalLog;
  17. use common\models\common\BalanceLog;
  18. use common\models\common\CommissionLog;
  19. use common\models\common\GlobalVarMap;
  20. use common\models\common\PlatformSetting;
  21. use common\models\common\UserBankCard;
  22. use common\models\mall\MallAddons;
  23. use common\models\order\Order;
  24. use common\models\order\OrderDetail;
  25. use common\models\user\User;
  26. use common\models\user\UserWallet;
  27. use common\models\common\CapitalStatistics;
  28. use addons\Coupon\common\models\AddonsCouponUserRelate;
  29. use addons\Store\common\models\StoreCouponUserRelate;
  30. use common\enums\ApiStatusEnum;
  31. use common\models\user\UserWithdrawLog;
  32. use common\models\statistics\UserStatistics;
  33. use common\enums\StatusEnum;
  34. use common\helpers\csv\CsvExportHelper;
  35. use common\enums\DownloadEnum;
  36. use common\models\user\BalanceRechargeLog;
  37. use yii\helpers\Json;
  38. class FinanceController extends MallController
  39. {
  40. public function actionIndex()
  41. {
  42. if (\Yii::$app->request->isAjax) {
  43. if (\Yii::$app->request->isPost) {
  44. $filename = '会员资产-' . date('YmdHis').'_'.rand(10000,99999);
  45. $data = \Yii::$app->request->post();
  46. $data['mall_id'] = $this->mall_id;
  47. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ASSETS,CapitalLog::class,'exportMemberAssets',$data);
  48. if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
  49. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  50. }
  51. $params = \Yii::$app->request->get();
  52. $where[] = ['status' => StatusEnum::ENABLED, 'mall_id' => $this->mall_id];
  53. if (!empty($params['user_id'])) $where[] = ['id' => trim($params['user_id'])];
  54. if (!empty($params['keyword'])) {
  55. $where[] = [
  56. 'or', ['like', 'nickname', trim($params['keyword'])], ['like', 'mobile', trim($params['keyword'])]
  57. ];
  58. }
  59. $params['where'] = $where;
  60. $params['select'] = 'id,nickname,avatar_url,mobile';
  61. $params['order'] = 'updated_at desc';
  62. $user_list = User::listPage($params);
  63. if(!empty($user_list['list'])){
  64. $user_id_arr = array_column($user_list['list'],'id');
  65. $user_wallet_list = UserWallet::lists([
  66. 'where'=>[['user_id'=>$user_id_arr]],
  67. 'select'=>'user_id,score,total_score,balance,total_balance,commission,total_commission',
  68. 'index'=>'user_id',
  69. ]);
  70. $is_install = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_COUPON);
  71. if($is_install) {
  72. $user_coupon_list = AddonsCouponUserRelate::lists([
  73. 'where'=>[['user_id'=>$user_id_arr], ['status' => [StatusEnum::ENABLED]]], // 过滤掉无效的优惠券
  74. 'select'=>'user_id,count(user_id) as coupon_count',
  75. 'group'=>'user_id',
  76. 'index'=>'user_id',
  77. ]);
  78. // 因为 StoreCouponUserRelate 是门店优惠券。所以需要判断门店插件是否是否安装
  79. $isStoreInstall = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE);
  80. $store_user_coupon_list = $store_can_user_coupon_list = []; // 因为下面用到两个字段判断。 所以初始为空
  81. if ($isStoreInstall) {
  82. $store_user_coupon_list = StoreCouponUserRelate::lists([
  83. 'where' => [['user_id' => $user_id_arr], ['status' => [StatusEnum::ENABLED]]],
  84. 'select' => 'user_id,count(user_id) as coupon_count',
  85. 'group' => 'user_id',
  86. 'index' => 'user_id',
  87. ]);
  88. $store_can_user_coupon_list = StoreCouponUserRelate::lists([
  89. 'where' => [['user_id' => $user_id_arr], ['status' => StatusEnum::ENABLED], ['coupon_status' => 2], ['is_use' => 0]],
  90. 'select' => 'user_id,count(user_id) as can_coupon_count',
  91. 'group' => 'user_id',
  92. 'index' => 'user_id',
  93. ]);
  94. }
  95. $can_user_coupon_list = AddonsCouponUserRelate::lists([
  96. 'where'=>[['user_id'=>$user_id_arr], ['status'=>StatusEnum::ENABLED], ['coupon_status'=>2], ['is_use'=>0]],
  97. 'select'=>'user_id,count(user_id) as can_coupon_count',
  98. 'group'=>'user_id',
  99. 'index'=>'user_id',
  100. ]);
  101. }
  102. foreach ($user_list['list'] as &$item){
  103. $item['score'] = $item['total_score'] = $item['balance'] = $item['total_balance'] = $item['commission'] = $item['total_commission'] =$item['coupon_count'] = 0;
  104. if(isset($user_wallet_list[$item['id']])){
  105. $item['score'] = $user_wallet_list[$item['id']]['score'];
  106. $item['total_score'] = $user_wallet_list[$item['id']]['total_score'];
  107. $item['balance'] = $user_wallet_list[$item['id']]['balance'];
  108. $item['total_balance'] = $user_wallet_list[$item['id']]['total_balance'];
  109. $item['commission'] = $user_wallet_list[$item['id']]['commission'];
  110. $item['total_commission'] = $user_wallet_list[$item['id']]['total_commission'];
  111. }
  112. if(isset($user_coupon_list[$item['id']])){
  113. $item['coupon_count'] = ($user_coupon_list[$item['id']]['coupon_count'] ?? 0) + ($store_user_coupon_list[$item['id']]['coupon_count'] ?? 0);
  114. $item['can_coupon_count'] = ($can_user_coupon_list[$item['id']]['can_coupon_count'] ?? 0) + ($store_can_user_coupon_list[$item['id']]['can_coupon_count'] ?? 0);
  115. }
  116. }
  117. //导出字段
  118. $user_list['export_list'] = CapitalLog::MEMBER_ASSETS_EXPORT_FIELD_LIST;
  119. }
  120. return $this->success('操作成功', $user_list);
  121. } else {
  122. return $this->render('index');
  123. }
  124. }
  125. /**
  126. * 资产概况-订单概况&支付统计
  127. *
  128. * @return mixed
  129. */
  130. public function actionStat()
  131. {
  132. date_default_timezone_set('PRC');
  133. if (\Yii::$app->request->isAjax) {
  134. $get = \Yii::$app->request->get();
  135. $res = \Yii::$app->services->validate->validate($get, [
  136. [['order_time'], 'safe'],
  137. ]);
  138. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  139. $params['where'][] = ['=', 'mall_id', $this->mall_id];
  140. if (isset($get['order_time']) && !empty($get['order_time'])) {
  141. $date = date($get['order_time'] . '-01');
  142. } else {
  143. $date = date('Y-m-01');
  144. }
  145. $start_time = strtotime($date);
  146. $end_time = strtotime($date . '+1 month -1 day 23:59:59');
  147. $params['where'][] = ['>=', 'created_at', $start_time];
  148. $params['where'][] = ['<=', 'created_at', $end_time];
  149. $list = UserStatistics::userOrderStatistics($params, $this->mall_id);//订单概况,支付统计
  150. $date = explode('-',$date)[0] . '-' . explode('-', $date)[1];
  151. $update_time = date('Y-m-d H:i:s');
  152. $config = \Yii::$app->services->setting->mall->get($this->mall_id, 'pay', true);
  153. $data = [];
  154. if(!empty($config)&&is_array($config)){
  155. foreach ($config as $k=>&$item){
  156. $item = json_decode($item,true);
  157. $data[$k]=[
  158. 'is_open'=>!empty($item['status'])?$item['status']:0,
  159. ];
  160. }
  161. }
  162. $is_install = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY);
  163. $data['joinpay_pay']['is_open'] = 0;
  164. if(!empty($is_install)){
  165. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic');
  166. $data['joinpay_pay']['is_open'] = !empty($settings['joinpay_status'])?$settings['joinpay_status']:0;
  167. }
  168. $month = date('Y-m',strtotime($date.' 05:00:00'));
  169. $data_cache = CensusMallSingleMonth::getCensusMallCache($this->mall_id,$month);
  170. if(!isset($data_cache['total_order_money'])) $data_cache = CensusMallSingleMonth::getCensusMall($this->mall_id,$month);
  171. $list['order_money'] = $data_cache['total_order_money']??0;
  172. if(!isset($data_cache['total_pay_money'])) $data_cache = CensusMallSingleMonth::getCensusMall($this->mall_id,$month);
  173. $list['pay_money'] = $data_cache['total_pay_money']??0;
  174. $list['not_pay_money'] = bcsub($list['order_money'],$list['pay_money'],2);
  175. $list['not_pay_money'] = $list['not_pay_money'] > 0 ? $list['not_pay_money'] : 0;
  176. if(!isset($data_cache['total_refund_money'])) $data_cache = CensusMallSingleMonth::getCensusMall($this->mall_id,$month);
  177. $list['refund_order_money'] = $data_cache['total_refund_money']??0;
  178. if(!isset($data_cache['total_deduction_money'])) $data_cache = CensusMallSingleMonth::getCensusMall($this->mall_id,$month);
  179. $list['deduction_money'] = $data_cache['total_deduction_money']??0;
  180. if(!isset($data_cache['total_recharge_money'])) $data_cache = CensusMallSingleMonth::getCensusMall($this->mall_id,$month);
  181. $list['recharge_money'] = $data_cache['total_recharge_money']??0;
  182. $payment_data = CensusMallPaymentSingleMonth::getCensusMallCache($this->mall_id,$month);
  183. return $this->success('操作成功', ['orderStatistics' => $list,'pay_config'=>$data,'payment_data'=>$payment_data, 'date' => $date, 'update_time' => $update_time]);
  184. } else {
  185. return $this->render('stat');
  186. }
  187. }
  188. /**
  189. * 资产概况-收支趋势图表数据(佣金收支)
  190. *
  191. * @return array
  192. */
  193. public function actionIncome() {
  194. if (\Yii::$app->request->isAjax) {
  195. $date_type = \Yii::$app->request->get('date_type') ?? 1;
  196. $search_type = [ 1 => 7, 2 => 30 ];
  197. $days = $search_type[$date_type] ?? 7; //默认查询7天
  198. CapitalLog::$capitalType = 'commission';
  199. $list = CapitalLog::incomeStatistics($days, $this->mall_id);
  200. //暂时不查统计表
  201. //$list = CapitalStatistics::incomeStatistics($days, $this->mall_id);
  202. return $this->success('succfess', $list);
  203. }
  204. }
  205. /**
  206. * 资产概况-订单概况&会员账户资产
  207. *
  208. * @return array
  209. */
  210. public function actionAccountAssets() {
  211. if (\Yii::$app->request->isAjax) {
  212. $census_mall_list = CensusMallCapital::lists(['where'=>[['mall_id' => $this->mall_id]],'index'=>'type'], true);
  213. $list['balance_total'] = $census_mall_list['balance']['surplus_nums']??0;
  214. $list['score_total'] = $census_mall_list['score']['surplus_nums']??0;
  215. $list['commission_total'] = $census_mall_list['commission']['surplus_nums']??0;
  216. return $this->success('操作成功', $list);
  217. }
  218. }
  219. /**
  220. * 积分明细
  221. * @author hpei
  222. */
  223. public function actionScoreLog()
  224. {
  225. date_default_timezone_set('PRC');
  226. if (\Yii::$app->request->isAjax) {
  227. if (\Yii::$app->request->isPost) {
  228. $filename = '积分列表-' . date('YmdHis') . '_' . rand(10000, 99999);
  229. $data = \Yii::$app->request->post();
  230. $data['table'] = 'score';
  231. $data['mall_id'] = $this->mall_id;
  232. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ASSETS,CapitalLog::class,'exportAssets',$data);
  233. if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
  234. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  235. }
  236. $get = \Yii::$app->request->get();
  237. $params['alias'] = 'b';
  238. $params['joinWith'] = ['user' => function($query){$query->select(['id', 'avatar_url', 'nickname', 'mobile']);}];
  239. if (isset($get['keyword']) && !empty($get['keyword'])) $params['where'] = [['or',['like','nickname',$get['keyword']],['=','mobile',$get['keyword']]]];
  240. if (isset($get['user_id']) && !empty($get['user_id'])) $params['where'][] = ['=', 'user_id', $get['user_id']];
  241. if (!empty($get['order_no'])){
  242. $order = Order::getOne([['order_no'=>$get['order_no']],['mall_id'=>$this->mall_id]],true,['detail']);
  243. if(!empty($order)){
  244. $order_detail_ids = array_column($order['detail'],'id');
  245. $params['where'][] = ['or', ['b.order_no' => $get['order_no']], ['b.source_table_id'=>$order_detail_ids]];
  246. } else {
  247. $params['where'][] = ['b.order_no'=>$get['order_no']];
  248. }
  249. }
  250. if (isset($get['desc']) && !empty($get['desc'])) $params['where'][] = ['like', 'b.desc', $get['desc']];
  251. if (isset($get['capital_type']) && !empty($get['capital_type'])) $params['where'][] = ['=', 'b.capital_type', $get['capital_type']];
  252. if (!empty($get['date'])) {
  253. $start_time = strtotime($get['date'][0]);
  254. $end_time = strtotime($get['date'][1]);
  255. $params['where'][] = ['>=', 'b.created_at', $start_time];
  256. $params['where'][] = ['<=', 'b.created_at', $end_time];
  257. }
  258. $params['where'][] = ['=', 'b.mall_id', $this->mall_id];
  259. $params['order'] = 'b.created_at desc,b.id desc';
  260. $params['limit'] = 20;
  261. $params['select'] = ['b.change_num', 'b.change_type', 'b.current_num','b.desc', 'b.capital_type','b.created_at', 'b.user_id', 'b.from_type','b.source_table_id','b.source_table'];
  262. CapitalLog::$capitalType = 'score';
  263. if ($get['status'] == 0) {
  264. CapitalLog::$capitalType = 'score_frozen';
  265. $params['where'][] = ['=', 'b.status',$get['status']];
  266. }
  267. $params['page'] = empty($get['page']) ? 1 : $get['page'];
  268. $pageData = CapitalLog::listPage($params, false);
  269. if ($pageData === false) return $this->error(CapitalLog::getStaticError());
  270. // $from_type_map = UserWalletEnum::getFromTypeMapByScore();
  271. $from_type_map = GlobalVarMap::getEnumMapByType('FromTypeMap');
  272. // $capital_type_map = UserWalletEnum::getCapitalTypeMapByScore();
  273. $capital_type_map = GlobalVarMap::getEnumMapByType('CapitalTypeMap');
  274. foreach ($pageData['list'] as &$val) {
  275. $val['source_text'] = ($from_type_map[$val['from_type']] ?? '').($capital_type_map[$val['capital_type']]?'-'.$capital_type_map[$val['capital_type']]:'');
  276. }
  277. $pageData['incomeCapitalTypeList'] = $capital_type_map;
  278. $where['where'] = [['=', 'mall_id', $this->mall_id], ['=', 'type', CapitalStatistics::SCORE]];
  279. $total = CapitalStatistics::statistics($where, ['sum(capital_total) capital_total', 'sum(expend_capital_total) expend_capital_total']);
  280. // $score = $total[0]['capital_total'] ? round($total[0]['capital_total'], 2) : 0;//总积分
  281. // $score_used = $total[0]['expend_capital_total'] ? round($total[0]['expend_capital_total'], 2) : 0;//已使用的积分
  282. // $score_no_used = $score - $score_used;
  283. // $pageData['total'] = ['score' => $score, 'score_used' => $score_used, 'score_no_used' => $score_no_used];
  284. $pageData['date'] = $get['date'];
  285. // 导出字段列表
  286. $pageData['export_list'] = CapitalLog::exportFieldsList();
  287. $type='score';
  288. $result = CensusMallCapital::findOne(['mall_id'=>$this->mall_id,'type'=>$type]);
  289. $pageData['total'] = ['score' => $result['total_nums']??0, 'score_used' => $result['use_nums']??0, 'score_no_used' => $result['surplus_nums']??0];
  290. return $this->success('操作成功', $pageData);
  291. } else {
  292. return $this->render('score-log');
  293. }
  294. }
  295. /**
  296. * 余额明细
  297. * @return mixed
  298. */
  299. public function actionBalanceLog()
  300. {
  301. date_default_timezone_set('PRC');
  302. CapitalLog::$capitalType = 'balance';
  303. if (\Yii::$app->request->isAjax) {
  304. if (\Yii::$app->request->isPost) {
  305. $filename = '余额列表-' . date('YmdHis') . '_' . rand(10000, 99999);
  306. $data = \Yii::$app->request->post();
  307. $data['table'] = 'balance';
  308. $data['mall_id'] = $this->mall_id;
  309. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ASSETS,CapitalLog::class,'exportAssets',$data);
  310. if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
  311. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  312. }
  313. $page = \Yii::$app->request->get('page') ?? 1;
  314. $limit = \Yii::$app->request->get('page_size') ?? $this->pageSize;
  315. $keyword = \Yii::$app->request->get('keyword');
  316. $user_id = \Yii::$app->request->get('user_id');
  317. $date = \Yii::$app->request->get('date');
  318. $remark = \Yii::$app->request->get('remark');
  319. $type = \Yii::$app->request->get('balance_from_type');
  320. $flag = \Yii::$app->request->get('flag');
  321. $order_no = \Yii::$app->request->get('order_no');
  322. $where[] = ['log.mall_id' => $this->mall_id];
  323. $where[] = ['log.status' => [0,1]];
  324. if (\Yii::$app->request->get('status') == 0) {
  325. //查询冻结表,未结算数据
  326. //$where[] = ['in', 'log.status', [-1, 0]];
  327. $where[] = ['in', 'log.status', [0]];
  328. CapitalLog::$capitalType = 'balance_frozen';
  329. }
  330. if (!empty($keyword)) $where[] = ['or', ['like', 'user.nickname', $keyword], ['like', 'user.mobile', $keyword]];
  331. if (!empty($user_id)) $where[] = ['log.user_id' => $user_id];
  332. if (!empty($remark)) $where[] = ['like', 'log.desc', $remark];
  333. if (!empty($type)) $where[] = ['log.capital_type' => $type];
  334. if (!empty($order_no)){
  335. $order = Order::getOne([['order_no'=>$order_no],['mall_id'=>$this->mall_id]],true,['detail']);
  336. if(!empty($order)){
  337. $order_detail_ids = array_column($order['detail'],'id');
  338. $where[] = ['or', ['log.order_no' => $order_no], ['log.source_table_id'=>$order_detail_ids]];
  339. } else {
  340. $where[] = ['log.order_no'=>$order_no];
  341. }
  342. }
  343. if (!empty($date)) {
  344. $start_time = strtotime($date[0]);
  345. $end_time = strtotime($date[1]);
  346. $where[] = ['>=', 'log.created_at', $start_time];
  347. $where[] = ['<=', 'log.created_at', $end_time];
  348. }
  349. $join = [
  350. ['LEFT JOIN', User::tableName() . 'as user', 'log.user_id = user.id and log.mall_id = user.mall_id'],
  351. ];
  352. $params = [
  353. 'alias' => 'log',
  354. 'select' => 'log.id,log.mall_id,log.user_id,log.change_type,log.from_type,log.capital_type,log.change_num,log.current_num,log.desc,log.source_table,log.source_table_id,log.created_at,user.nickname,user.avatar_url,user.mobile,user.username',
  355. 'join' => $join,
  356. 'where' => $where,
  357. 'order' => 'log.created_at desc,log.id desc',
  358. 'page' => $page,
  359. 'limit' => $limit,
  360. ];
  361. if ($flag == "EXPORT") {
  362. } else {
  363. $list = CapitalLog::listPage($params, false, true);
  364. }
  365. // $capital_type_map = UserWalletEnum::getCapitalTypeMapByBalance();
  366. // $from_type_map = UserWalletEnum::getFromTypeMapByBalance();
  367. $from_type_map = GlobalVarMap::getEnumMapByType('FromTypeMap');
  368. $capital_type_map = GlobalVarMap::getEnumMapByType('CapitalTypeMap');
  369. if (!empty($list['list'])) {
  370. foreach ($list['list'] as &$v) {
  371. $v['source_text'] = ($from_type_map[$v['from_type']] ?? '').($capital_type_map[$v['capital_type']]?'-'.$capital_type_map[$v['capital_type']]:'');
  372. $v['created_at'] = date("Y-m-d H:i:s", $v["created_at"]);
  373. };
  374. }
  375. // 业务类型
  376. $list['incomeCapitalTypeList'] = $capital_type_map;
  377. // 导出字段列表
  378. $list['export_list'] = CapitalLog::exportFieldsList();
  379. $where['where'] = [['=', 'mall_id', $this->mall_id], ['=', 'type', CapitalStatistics::BALANCE]];
  380. $total = CapitalStatistics::statistics($where,
  381. ['sum(capital_total) capital_total', //总额
  382. 'sum(expend_capital_total) expend_capital_total', //使用总额
  383. 'sum(cash_out_total) cash_out_total', //提现额
  384. 'sum(service_charges_tatoal) service_charges_tatoal']);//手续费
  385. // $statistics_data['income_capital_total'] = $total[0]['capital_total'] ? round($total[0]['capital_total'], 2) : 0;
  386. // $statistics_data['expend_capital_total'] = $total[0]['expend_capital_total'] ? round($total[0]['expend_capital_total'], 2) : 0;
  387. // $statistics_data['cash_out_total'] = $total[0]['cash_out_total'] ? round($total[0]['cash_out_total'], 2) : 0;
  388. // $statistics_data['service_charges_tatoal'] = $total[0]['service_charges_tatoal'] ? round($total[0]['service_charges_tatoal'], 2) : 0;
  389. // $statistics_data['available_capital_total'] = UserWallet::find()->where(['mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED])->sum('balance');
  390. // $statistics_data['available_capital_total'] = $statistics_data['available_capital_total'] ? round($statistics_data['available_capital_total'], 2) : 0;
  391. $list['date'] = $date;
  392. $type='balance';
  393. $result = CensusMallCapital::findOne(['mall_id'=>$this->mall_id,'type'=>$type]);
  394. $statistics_data['income_capital_total'] = $result['total_nums']??0;
  395. $statistics_data['expend_capital_total'] = $result['use_nums']??0;
  396. $statistics_data['available_capital_total'] = $result['surplus_nums']??0;
  397. $statistics_data['cash_out_total'] = $result['withdrawal_nums']??0;
  398. $list['statistics_data'] = $statistics_data;
  399. return $this->success('操作成功', $list);
  400. }
  401. return $this->render('balance-log');
  402. }
  403. /**
  404. * 佣金明细
  405. */
  406. public function actionCommissionLog()
  407. {
  408. date_default_timezone_set('PRC');
  409. CapitalLog::$capitalType = 'commission';
  410. if (\Yii::$app->request->isAjax) {
  411. if (\Yii::$app->request->isPost) {
  412. $filename = '佣金列表-' . date('YmdHis') . '_' . rand(10000, 99999);
  413. $data = \Yii::$app->request->post();
  414. $data['table'] = 'commission';
  415. $data['mall_id'] = $this->mall_id;
  416. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ASSETS,CapitalLog::class,'exportAssets',$data);
  417. if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
  418. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  419. }
  420. $page = \Yii::$app->request->get('page') ?? 1;
  421. $limit = \Yii::$app->request->get('page_size') ?? $this->pageSize;
  422. $get = \Yii::$app->request->get();
  423. $params[] = ['log.mall_id' => $this->mall_id];
  424. if ($get['status'] == 0) {
  425. //查询冻结表,未结算数据
  426. $params[] = ['in', 'log.status', [ 0]];
  427. CapitalLog::$capitalType = 'commission_frozen';
  428. }
  429. if (!empty($get['keyword'])){
  430. $user_list = User::lists(['where'=>[['mall_id'=>$this->mall_id], ['or', ['like', 'nickname', $get['keyword']], ['like', 'mobile', $get['keyword']]]],'select'=>'id']);
  431. if(!empty($user_list)){
  432. $user_ids = array_column($user_list,'id');
  433. $params[] = ['log.user_id' => $user_ids];
  434. }else{
  435. $params[] = ['log.user_id' => []];
  436. }
  437. }
  438. if (!empty($get['user_id'])) $params[] = ['log.user_id' => $get['user_id']];
  439. if (!empty($get['order_no'])){
  440. if(substr($get['order_no'], 0, 1) == 'C'){
  441. // 对收银台做单独处理
  442. $cashier_order_class = \addons\Store\common\models\StoreCashierOrder::class;
  443. $tmp_capital_log = CapitalLog::find()->where(['or', ['source_table' => 'store_cashier_order'], ['source_table' => $cashier_order_class::tableName()]])
  444. ->andWhere(['and', ['order_no'=>$get['order_no']], ['mall_id'=>$this->mall_id]])
  445. ->select('id')
  446. ->column();
  447. $params[] = ['in','log.id',$tmp_capital_log ?? []];
  448. }else{
  449. $order_detail_ids = [];
  450. $order = Order::getOne([['order_no'=>$get['order_no']],['mall_id'=>$this->mall_id]],true,['detail']);
  451. if(!empty($order)){
  452. $order_detail_ids = array_column($order['detail'],'id');
  453. }
  454. $params[] = ['log.source_table_id'=>$order_detail_ids];
  455. }
  456. }
  457. if (!empty($get['capital_type'])) $params[] = ['log.capital_type' => $get['capital_type']];
  458. if(!empty($get['order_num'])) $params[] = ['log.order_no'=>$get['order_num']];//订单号查询
  459. if (!empty($get['date'])) {
  460. $start_time = strtotime($get['date'][0]);
  461. $end_time = strtotime($get['date'][1]);
  462. $params[] = ['>=', 'log.created_at', $start_time];
  463. $params[] = ['<=', 'log.created_at', $end_time];
  464. }
  465. //过滤该插件
  466. $params[]= ['!=', 'from_type', AddonsEnum::ADDONS_NAME_NI_BAO_ACHIEVEMENT];
  467. $params = [
  468. 'alias' => 'log',
  469. 'select' => 'log.id,log.mall_id,log.user_id,log.change_type,log.change_num,log.current_num,log.desc,log.from_type,log.capital_type,log.created_at,log.order_no,source_table,source_table_id',
  470. 'with'=>['user'],
  471. 'where' => $params,
  472. 'order' => 'log.created_at desc,log.id desc',
  473. 'page' => $page,
  474. 'limit' => $limit,
  475. ];
  476. $list = CapitalLog::listPage($params, false, true);
  477. // $commission_map = UserWalletEnum::getCommissionMap();
  478. $commission_map = GlobalVarMap::getEnumMapByType('FromTypeMap');
  479. $list['date'] = $get['date'];
  480. // $capital_type_map = UserWalletEnum::getCapitalTypeMapByCommission();
  481. $capital_type_map = GlobalVarMap::getEnumMapByType('CapitalTypeMap');
  482. if (!empty($list['list'])) {
  483. $douyin_cps_ids = [];
  484. /** @var \addons\DouyinCps\common\models\DouyinCpsOrder $douyin_cps_class */
  485. $douyin_cps_class = \addons\DouyinCps\common\models\DouyinCpsOrder::class;
  486. //user.nickname,user.avatar_url,user.mobile,user.username
  487. foreach ($list['list'] as &$lv) {
  488. $lv['nickname'] = '';
  489. $lv['avatar_url'] = '';
  490. $lv['mobile'] = '';
  491. $lv['username'] = '';
  492. if(!empty($lv['user'])){
  493. $lv['nickname'] = $lv['user']['nickname'];
  494. $lv['avatar_url'] = $lv['user']['avatar_url'];
  495. $lv['mobile'] = $lv['user']['mobile'];
  496. $lv['username'] = $lv['user']['username'];
  497. }
  498. $lv['source_text'] = ($commission_map[$lv['from_type']] ?? '').($capital_type_map[$lv['capital_type']]?'-'.$capital_type_map[$lv['capital_type']]:'');
  499. $lv['created_at'] = date('Y-m-d H:i:s', $lv['created_at']);
  500. // 获取订单号
  501. if ($lv['source_table'] == 'order_detail' || $lv['source_table'] == OrderDetail::tableName()) {
  502. $detail_ids[] = $lv['source_table_id'];
  503. } elseif (class_exists((string)$douyin_cps_class) && $lv['source_table'] == $douyin_cps_class::tableName()) {
  504. $douyin_cps_ids[] = $lv['source_table_id'];
  505. } elseif ($lv['source_table'] == 'order' || $lv['source_table'] == '{{%order}}') {
  506. $order_ids[] = $lv['source_table_id'];
  507. }
  508. }
  509. // 根据订单详情ID获取订单号
  510. if (!empty($detail_ids)) {
  511. $order_params = [
  512. 'where' => [
  513. ['id' => $detail_ids]
  514. ],
  515. 'with' => ['user', 'order'],
  516. 'select' => 'id,user_id,order_id',
  517. 'index' => 'id'
  518. ];
  519. $commission_orders = OrderDetail::lists($order_params, true);
  520. // print_r($commission_orders);exit;
  521. foreach ($list['list'] as &$item) {
  522. if ($item['source_table'] == 'order_detail' || $item['source_table'] == OrderDetail::tableName()) {
  523. if (!empty($commission_orders[$item['source_table_id']])) {
  524. $item['order_no'] = $commission_orders[$item['source_table_id']]['order']['order_no'];
  525. $item['buy_user'] = [
  526. 'id' => $commission_orders[$item['source_table_id']]['user']['id'],
  527. 'nickname' => $commission_orders[$item['source_table_id']]['user']['nickname'],
  528. 'avatar_url' => $commission_orders[$item['source_table_id']]['user']['avatar_url']
  529. ];
  530. }
  531. }
  532. }
  533. }
  534. //显示佣金数据来源为order表的下单用户数据
  535. if (!empty($order_ids)) {
  536. $order_params = [
  537. 'where' => [
  538. ['id' => $order_ids]
  539. ],
  540. 'with' => ['user'],
  541. 'select' => 'id,user_id,order_no',
  542. 'index' => 'id'
  543. ];
  544. $commission_orders = Order::lists($order_params, true);
  545. // print_r($commission_orders);exit;
  546. foreach ($list['list'] as $key => $item2) {
  547. if ($item2['source_table'] == 'order' || $item2['source_table'] == '{{%order}}') {
  548. // print_r($item2);exit;
  549. if (!empty($commission_orders[$item2['source_table_id']])) {
  550. $list['list'][$key]['order_no'] = $commission_orders[$item2['source_table_id']]['order_no'];
  551. $list['list'][$key]['buy_user'] = [
  552. 'id' => $commission_orders[$item2['source_table_id']]['user']['id'],
  553. 'nickname' => $commission_orders[$item2['source_table_id']]['user']['nickname'],
  554. 'avatar_url' => $commission_orders[$item2['source_table_id']]['user']['avatar_url']
  555. ];
  556. }
  557. }
  558. }
  559. }
  560. if (!empty($douyin_cps_ids)) {
  561. $commission_orders = $douyin_cps_class::getOrderNoByIds(array_unique($douyin_cps_ids));
  562. foreach ($list['list'] as &$item) {
  563. if ($item['source_table'] == $douyin_cps_class::tableName()) {
  564. $item['order_no'] = $commission_orders[$item['source_table_id']];
  565. }
  566. }
  567. }
  568. }
  569. // 业务类型
  570. $list['commissionFromTypeList'] = $commission_map;//来源类型
  571. $list['incomeCapitalTypeList'] = $capital_type_map;//佣金类型
  572. // 导出字段列表
  573. $list['export_list'] = CommissionLog::EXPORT_FIELD_LIST;
  574. $where['where'] = [['=', 'mall_id', $this->mall_id], ['=', 'type', CapitalStatistics::COMMISSIOIN]];
  575. // $total = CapitalStatistics::statistics($where,
  576. // ['sum(capital_total) capital_total', //总额
  577. // 'sum(invalid_capital_total) invalid_capital_total']);//无效额
  578. // $statistics_data['commission_total'] = $total[0]['capital_total'] ? round($total[0]['capital_total'], 2) : 0;
  579. // $statistics_data['invalid_capital_total'] = $total[0]['invalid_capital_total'] ? round($total[0]['invalid_capital_total'], 2) : 0;
  580. CapitalLog::$capitalType = 'commission_frozen';
  581. $statistics_list = CapitalLog::find()->where(['mall_id' => $this->mall_id, 'status' => 0])->asArray()->all();
  582. if (empty($statistics_list)) {
  583. // $statistics_data['frozen_capital_total'] = 0;
  584. } else {
  585. // foreach ($statistics_list as $val) {
  586. // if ($val['change_type'] == 'add') $statistics_data['frozen_capital_total'] += $val['change_num'];
  587. // if ($val['change_type'] == 'sub') $statistics_data['frozen_capital_total'] -= $val['change_num'];
  588. // }
  589. // $statistics_data['frozen_capital_total'] = round($statistics_data['frozen_capital_total'], 2);
  590. }
  591. $type='commission';
  592. $result = CensusMallCapital::findOne(['mall_id'=>$this->mall_id,'type'=>$type]);
  593. $total_nums = $result['total_nums']??0;
  594. $unsettled = $result['unsettled']??0;
  595. $surplus_nums = $result['surplus_nums']??0;
  596. $statistics_data['commission_total'] = $total_nums+$unsettled;
  597. $statistics_data['frozen_capital_total'] = $unsettled;
  598. $statistics_data['settled_commission_total'] = $surplus_nums;
  599. // $statistics_data['settled_commission_total'] = $total_nums;
  600. $statistics_data['invalid_capital_total'] = $result['cancel_nums']??0;
  601. $list['statistics_data'] = $statistics_data;
  602. $list['export_list'] = CapitalLog::exportFieldsList();
  603. return $this->success('操作成功', $list);
  604. } else {
  605. $flag = \Yii::$app->request->post('flag');
  606. if (empty($flag)) {
  607. return $this->render('commission-log');
  608. } else {
  609. // 导出数据
  610. }
  611. }
  612. }
  613. /**
  614. * @Author: 广东七件事 ganxiaohao
  615. * @Date: 2020-05-15
  616. * @Time: 9:58
  617. * @Note:提现记录
  618. * @return string|\yii\web\Response
  619. */
  620. public function actionCash()
  621. {
  622. if (\Yii::$app->request->isAjax) {
  623. if (\Yii::$app->request->isPost) {
  624. if (\Yii::$app->request->post('flag') === 'EXPORT') {
  625. $post = \Yii::$app->request->post();
  626. if (isset($post['status']) && ($post['status'] == -1 || $post['status'] === '')) unset($post['status']);
  627. $post['mall_id'] = $this->mall_id;
  628. $filename = '提现审核-' . date('YmdHis').'_'.rand(10000,99999);
  629. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_CASHDRAW_AUDIT,UserWithdrawLog::class,'exportHandle',$post);
  630. if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
  631. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  632. }
  633. } else {
  634. $log = new UserWithdrawLog();
  635. $params = \Yii::$app->request->get();
  636. $params['mall_id'] = $this->mall_id;
  637. $logs = $log->searchLogList($params);
  638. //公告调用:提现是否需要验证码
  639. $need_risk = GlobalInvoke::exec(GlobalInvoke::WITHDRAW_RISK, $this->mall_id, ['mall_id' => $this->mall_id]);
  640. $mobile = '';
  641. if($need_risk && $need_risk['is_enable']){
  642. // //该商城的管理员
  643. // $mall_admin = Admin::findOne(['status' => StatusEnum::ENABLED,'mall_id' => $this->mall_id,'is_default' => 1]);
  644. // $mobile = $mall_admin->account;
  645. $mobile = $need_risk['cash_mobile'];
  646. }
  647. // 统计
  648. list(
  649. $audit_commision,
  650. $pending_commision,
  651. $paid_commision,
  652. $rejected_commision,
  653. $total_commision
  654. ) = UserWithdrawLog::getWithdrawLogStatistic($this->mall_id);
  655. $data = [
  656. 'list' => $logs['data']['list'],
  657. 'export_list' => $logs['data']['export_list'],
  658. 'pagination' => $logs['data']['pagination'],
  659. 'need_risk' => $need_risk ? $need_risk['is_enable'] : false,
  660. 'mobile' => $mobile,
  661. 'statistic' => compact(
  662. 'audit_commision', 'pending_commision', 'paid_commision', 'rejected_commision', 'total_commision'
  663. ),
  664. 'mall_id' => $this->mall_id,
  665. ];
  666. // 更改为调用统一提现方法
  667. $data['DefaultWithDrawWayMap'] = UserWithdrawLog::getUserWithdrawType($this->mall_id);
  668. $data['DefaultWithDrawWayMap']['alipay'] = '支付宝线下转账';
  669. $data['withdraw_from_list'] = [
  670. ['key' => '0', 'label' => "全部", 'value' => ""],
  671. ['key' => '2', 'label' => "余额", 'value' => "2"],
  672. ['key' => '1', 'label' => "佣金", 'value' => "1"],
  673. ['key' => '3', 'label' => "货款", 'value' => "3"],
  674. ['key' => '4', 'label' => "积分", 'value' => "4"],
  675. ['key' => '9', 'label' => "积分增长赢", 'value' => "9"],
  676. ];
  677. if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_HUI_DIAN)) {
  678. $huidian_custom_name = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_HUI_DIAN, 'basic.custom_name');
  679. $data['withdraw_from_list'][] = ['key' => '10', 'label' => $huidian_custom_name . '提现', 'value' => "10"];
  680. }
  681. return $this->success('success', $data, ApiStatusEnum::CODE_SUCCESS, 0);
  682. }
  683. }else{
  684. }
  685. return $this->render('cash');
  686. }
  687. /**
  688. * @Author: 广东七件事 ganxiaohao
  689. * @Date: 2020-05-30
  690. * @Time: 10:15
  691. * @Note:提现处理
  692. * @throws \Exception
  693. */
  694. public function actionCashApply()
  695. {
  696. try {
  697. if (\Yii::$app->request->isAjax) {
  698. if (\Yii::$app->request->isPost) {
  699. $post = \Yii::$app->request->post();
  700. if($post['status'] == 2){
  701. $check = $this->checkCashRisk($post);
  702. if(!$check){
  703. return $this->error('验证码错误');
  704. }
  705. }
  706. $form = new UserWithdrawLog();
  707. $form->attributes = \Yii::$app->request->post();
  708. $res = $form->updateLog();
  709. if($res) return $this->success('操作成功',['res'=>$res]);
  710. return $this->error('错误');
  711. }
  712. }
  713. }catch (\Exception $e){
  714. return $this->error($e->getMessage());
  715. }
  716. }
  717. /**
  718. * 批量审核处理
  719. * @Author: lun
  720. * @DateTime: 2022/7/16 0016 15:31
  721. * @Copyright: copyright (c) 2021 广东七件事集团
  722. */
  723. public function actionBatchCashApply()
  724. {
  725. try {
  726. $request = \Yii::$app->request;
  727. if ($request->isAjax && $request->isPost) {
  728. $params = $request->post();
  729. // 检查提交的参数
  730. $res = \Yii::$app->services->validate->validate($params,[
  731. [['ids', 'status'], 'required'],
  732. [['status'], 'integer'],
  733. [['content'], 'string'],
  734. ['ids', 'safe']
  735. ]);
  736. if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  737. $ids = $params['ids'];// 上传的提现记录id
  738. foreach ($ids as $id) {
  739. $model = UserWithdrawLog::findOne(['id' => $id]);
  740. if ($model) {
  741. $model->status = $params['status'];
  742. $model->content = $params['content']??'';
  743. $res = $model->updateLog();// 处理提现
  744. if ($res === false) throw new \Exception($model->getErrorMessage());
  745. }
  746. }
  747. }
  748. return $this->success('批量操作成功');
  749. } catch (\Exception $e) {
  750. return $this->error('批量操作失败:'.$e->getMessage());
  751. }
  752. }
  753. // 支付宝代付提现
  754. public function actionAlitopay(){
  755. $data = $this->request->post();
  756. $data['mall_id'] = $this->mall_id;
  757. $data['log_id'] = is_string($data['id']) ? explode(',',$data['id']) : $data["id"];
  758. // $data['log_id'] = [272,274];
  759. $service = new WithdrawalService($data);
  760. $res = $service->aliToPay();
  761. if ($res === false){
  762. return $this->error($service->error);
  763. }
  764. return $this->success('操作成功',['res'=>$res]);
  765. }
  766. // 代税宝提现
  767. public function actionAvoidtax(){
  768. $data = $this->request->post();
  769. $data['mall_id'] = $this->mall_id;
  770. $data['log_id'] = is_string($data['id']) ? explode(',',$data['id']) : $data["id"];
  771. $service = new WithdrawalService($data);
  772. $res = $service->avoidtaxToPay();
  773. if ($res === false){
  774. return $this->error($service->error);
  775. }
  776. return $this->success('操作成功',['res'=>$res]);
  777. }
  778. /**
  779. * 检查 支付宝代付、代税宝 插件是否开启
  780. */
  781. public function actionCheckChannel(){
  782. $res = GlobalInvoke::exec(GlobalInvoke::INVOKE_WITHDRAW_WITHDRAWAL_CHANNEL,$this->mall_id,[
  783. 'mall_id'=>$this->mall_id
  784. ]);
  785. return $this->success('操作成功',$res);
  786. }
  787. /**
  788. * 银典支付
  789. *
  790. * @return void
  791. */
  792. public function actionYunfastPay()
  793. {
  794. if ($this->request->isPost) {
  795. $data = $this->request->post();
  796. $data['mall_id'] = $this->mall_id;
  797. $data['log_id'] = is_string($data['id']) ? explode(',',$data['id']) : $data["id"];
  798. $service = new WithdrawalService($data);
  799. $res = $service->yunfastPay();
  800. return $res === false
  801. ? $this->error($service->error)
  802. : $this->success(sprintf('%s笔订单打款中', count($res)));
  803. }
  804. }
  805. /**
  806. * 检测是否需要手机验证码
  807. * @param $params
  808. * @return bool
  809. */
  810. private function checkCashRisk($params)
  811. {
  812. //打款操作:检测是否需要手机验证码,全局调用
  813. $need_risk = GlobalInvoke::exec(GlobalInvoke::WITHDRAW_RISK, $this->mall_id, ['mall_id' => $this->mall_id]);
  814. if($need_risk && $need_risk['is_enable']){
  815. if(empty($params['verification_code'])){
  816. return false;
  817. }
  818. $check = GlobalInvoke::exec(GlobalInvoke::WITHDRAW_RISK_CAPTCHA, $this->mall_id, ['mall_id' => $this->mall_id,'cash_id' => $params['id'],'captcha' => $params['verification_code']]);
  819. if(!$check['status']){
  820. return false;
  821. }
  822. }
  823. return true;
  824. }
  825. /**
  826. * @Author: 广东七件事 ganxiaohao
  827. * @Date: 2020-05-15
  828. * @Time: 9:58
  829. * @Note:充值记录
  830. * @return string|\yii\web\Response
  831. */
  832. public function actionRechargeAudit()
  833. {
  834. if (\Yii::$app->request->isAjax) {
  835. if (\Yii::$app->request->isGet) {
  836. $get = \Yii::$app->request->get();
  837. $params['order'] = 'id desc';
  838. $params['alias'] = 'b';
  839. $params['joinWith'] = ['user'];
  840. if (isset($get['status']) && $get['status'] != -1) {
  841. $params['where'][] = ['=', 'b.withdraw_status', $get['status']];
  842. }
  843. if (!empty($get['keyword'])) {
  844. $params['where'] = [[
  845. 'or',
  846. ['like', 'nickname', $get['keyword']],
  847. ['like', 'mobile', $get['keyword']]
  848. ]];
  849. }
  850. if (!empty($get['user_id'])) {
  851. $params['where'][] = ['=', 'user_id', $get['user_id']];
  852. }
  853. if (!empty($get['start_date']) && !empty($get['end_date'])) {
  854. $get['start_date'] = str_replace('+', ' ', $get['start_date']);
  855. $get['end_date'] = str_replace('+', ' ', $get['end_date']);
  856. $params['where'][] = ['>=', 'b.created_at', strtotime($get['start_date'])];
  857. $params['where'][] = ['<=', 'b.created_at', strtotime($get['end_date'])];
  858. }
  859. $params['where'][] = ['=', 'b.mall_id', $this->mall_id];
  860. $params['order'] = ['id' => SORT_DESC];
  861. $params['limit'] = 10;
  862. $list = BalanceRechargeLog::listPage($params);
  863. return $this->success('操作成功',$list);
  864. }
  865. }
  866. return $this->render('recharge-audit');
  867. }
  868. /**
  869. * @Author: 广东七件事 ganxiaohao
  870. * @Date: 2020-05-30
  871. * @Time: 10:15
  872. * @Note:提现处理
  873. * @throws \Exception
  874. */
  875. public function actionRechargeApply()
  876. {
  877. try {
  878. if (\Yii::$app->request->isAjax) {
  879. if (\Yii::$app->request->isPost) {
  880. $post = \Yii::$app->request->post();
  881. $res = BalanceRechargeLog::updateLog($post);
  882. if($res) return $this->success('操作成功',['res'=>$res]);
  883. return $this->error(BalanceRechargeLog::getStaticError());
  884. }
  885. }
  886. }catch (\Exception $e){
  887. return $this->error($e->getMessage());
  888. }
  889. }
  890. /**
  891. * 银行卡合规提现处理
  892. *
  893. * @return string
  894. */
  895. public function actionBanktax()
  896. {
  897. $data = $this->request->post();
  898. $data['mall_id'] = $this->mall_id;
  899. $data['log_id'] = is_string($data['id']) ? explode(',', $data['id']) : $data['id'];
  900. $service = new WithdrawalService($data);
  901. $res = $service->banktaxToPay();
  902. if ($res === false) {
  903. return $this->error($service->error);
  904. }
  905. return $this->success('操作成功', ['res' => $res]);
  906. }
  907. /**
  908. * 资产概况-订单概况&会员账户资产(每日)
  909. *
  910. * @return array
  911. */
  912. public function actionAccountAssetsDaily()
  913. {
  914. try {
  915. if (\Yii::$app->request->isAjax) {
  916. if (\Yii::$app->request->isGet) {
  917. $get = \Yii::$app->request->get();
  918. $date = $get['date'];
  919. $first = CensusMallCapitalStatistics::find()->where([
  920. 'mall_id' => $this->mall_id
  921. ])->asArray()->one();
  922. if ($first) {
  923. $start_date = date('Y-m-d', ($first['created_at']-86400));
  924. }
  925. if ($date) {
  926. $statistics = CensusMallCapitalStatistics::find()->where([
  927. 'mall_id' => $this->mall_id,
  928. 'statistics_date' => $date,
  929. 'status' => StatusEnum::ENABLED
  930. ])->asArray()->one();
  931. }
  932. return $this->success('操作成功', [
  933. 'limit_date' => $start_date ?? date('Y-m-d', time()),
  934. 'balance_surplus_nums' => $statistics['balance_surplus_nums'] ?? 0,
  935. 'commission_surplus_nums' => $statistics['commission_surplus_nums'] ?? 0,
  936. 'score_surplus_nums' => $statistics['score_surplus_nums'] ?? 0,
  937. ]);
  938. }
  939. }
  940. }catch (\Exception $e){
  941. return $this->error($e->getMessage());
  942. }
  943. }
  944. public function actionLinggong()
  945. {
  946. $data = $this->request->post();
  947. $data['mall_id'] = $this->mall_id;
  948. $data['log_id'] = is_string($data['id']) ? explode(',', $data['id']) : $data['id'];
  949. $service = new WithdrawalService($data);
  950. $res = $service->linggongToPay($data);
  951. if ($res === false) {
  952. return $this->error($service->error);
  953. }
  954. return $this->success('操作成功', ['res' => $res]);
  955. }
  956. }