FinanceController.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace backendApi\modules\v1\controllers;
  9. use backendApi\modules\v1\models\Admin;
  10. use backendApi\modules\v1\models\AdminCountry;
  11. use backendApi\modules\v1\models\AdminRole;
  12. use backendApi\modules\v1\models\exportForms\FinanceExportForm;
  13. use backendApi\modules\v1\models\lists\finance\BalanceAuditList;
  14. use backendApi\modules\v1\models\lists\finance\HistoryBonusList;
  15. use backendApi\modules\v1\models\lists\finance\RechargeList;
  16. use backendApi\modules\v1\models\lists\finance\TransferList;
  17. use backendApi\modules\v1\models\lists\finance\WithdrawList;
  18. use common\helpers\Cache;
  19. use common\helpers\Date;
  20. use common\helpers\Excel;
  21. use common\helpers\Log;
  22. use common\helpers\Tool;
  23. use common\helpers\user\Info;
  24. use common\models\BalanceAudit;
  25. use common\models\DealType;
  26. use common\models\forms\ChangeBalanceForm;
  27. use common\models\forms\ChangePerfForm;
  28. use common\models\forms\DealTypeForm;
  29. use common\models\forms\InvoiceAuditForm;
  30. use common\models\forms\InvoiceBalanceAuditForm;
  31. use common\models\forms\RechargeForm;
  32. use common\models\forms\WithdrawForm;
  33. use common\models\HistoryBonus;
  34. use common\models\InvoiceAudit;
  35. use common\models\InvoiceBalanceAudit;
  36. use common\models\InvoiceFlow;
  37. use common\models\OpenBank;
  38. use common\models\PerfAudit;
  39. use common\models\PerfPeriod;
  40. use common\models\Recharge;
  41. use common\models\RegType;
  42. use common\models\DecRole;
  43. use common\models\Region;
  44. use common\models\Transfer;
  45. use common\models\Uploads;
  46. use common\models\User;
  47. use common\models\UserBonus;
  48. use common\models\UserInfo;
  49. use common\models\UserPerf;
  50. use common\models\UserSystem;
  51. use common\models\Withdraw;
  52. use Yii;
  53. use common\helpers\Bonus;
  54. use common\helpers\bonus\BonusCalc;
  55. use common\helpers\Form;
  56. use common\models\FlowBonus;
  57. use common\models\forms\PeriodForm;
  58. use common\models\Period;
  59. class FinanceController extends BaseController {
  60. public $modelClass = FlowBonus::class;
  61. public function behaviors() {
  62. $behaviors = parent::behaviors();
  63. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  64. return $behaviors;
  65. }
  66. /**
  67. * 会员余额变动审核列表
  68. * @return mixed
  69. * @throws \yii\base\Exception
  70. * @throws \yii\web\HttpException
  71. */
  72. public function actionBalanceAuditList() {
  73. $filter = $this->filterCondition([
  74. 'USER_NAME' => 'U.USER_NAME',
  75. 'REAL_NAME' => 'U.REAL_NAME',
  76. 'userIds' => 'BA.USER_ID',
  77. 'filterStatus' => 'BA.AUDIT_STATUS',
  78. 'LAST_DEC_LV_NAME' => 'BA.LAST_DEC_LV',
  79. 'LAST_DEC_ROLE_NAME' => 'BA.LAST_DEC_ROLE_ID',
  80. 'LAST_EMP_LV_NAME' => 'BA.LAST_EMP_LV',
  81. 'TYPE_NAME' => 'BA.TYPE',
  82. 'DEAL_TYPE_NAME' => 'BA.DEAL_TYPE',
  83. 'AMOUNT' => 'BA.AMOUNT',
  84. 'CREATE_REMARK' => 'BA.CREATE_REMARK',
  85. 'REMARK_IS_SHOW' => 'BA.REMARK_IS_SHOW',
  86. 'CREATED_AT' => 'BA.CREATED_AT',
  87. 'AUDITED_AT' => 'BA.AUDITED_AT',
  88. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  89. 'AUDIT_ADMIN_NAME' => 'ADMU.ADMIN_NAME',
  90. //4047 国家筛选
  91. 'COUNTRY' => 'U.COUNTRY_ID',
  92. ]);
  93. $condition = $filter['condition'];
  94. $params = $filter['params'];
  95. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  96. if (!$isSuper) {
  97. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  98. $adminCountry = AdminCountry::getCountry($adminId);
  99. $quotedAdminCountry = array_map(function($item) {
  100. return "'" . addslashes($item) . "'";
  101. }, $adminCountry);
  102. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  103. }
  104. $listObj = new BalanceAuditList();
  105. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  106. return static::notice($data);
  107. }
  108. /**
  109. * 会员余额调整列表导出
  110. * @return mixed
  111. * @throws \yii\db\Exception
  112. * @throws \yii\web\HttpException
  113. */
  114. public function actionBalanceAuditListExport() {
  115. $filter = $this->filterCondition([
  116. 'USER_NAME' => 'U.USER_NAME',
  117. 'REAL_NAME' => 'U.REAL_NAME',
  118. 'userIds' => 'BA.USER_ID',
  119. 'filterStatus' => 'BA.AUDIT_STATUS',
  120. 'LAST_DEC_LV_NAME' => 'BA.LAST_DEC_LV',
  121. 'LAST_DEC_ROLE_NAME' => 'BA.LAST_DEC_ROLE_ID',
  122. 'LAST_EMP_LV_NAME' => 'BA.LAST_EMP_LV',
  123. 'TYPE_NAME' => 'BA.TYPE',
  124. 'DEAL_TYPE_NAME' => 'BA.DEAL_TYPE',
  125. 'AMOUNT' => 'BA.AMOUNT',
  126. 'CREATE_REMARK' => 'BA.CREATE_REMARK',
  127. 'REMARK_IS_SHOW' => 'BA.REMARK_IS_SHOW',
  128. 'CREATED_AT' => 'BA.CREATED_AT',
  129. 'AUDITED_AT' => 'BA.AUDITED_AT',
  130. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  131. 'AUDIT_ADMIN_NAME' => 'ADMU.ADMIN_NAME',
  132. ]);
  133. $condition = $filter['condition'];
  134. $params = $filter['params'];
  135. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  136. if (!$isSuper) {
  137. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  138. $adminCountry = AdminCountry::getCountry($adminId);
  139. $quotedAdminCountry = array_map(function($item) {
  140. return "'" . addslashes($item) . "'";
  141. }, $adminCountry);
  142. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  143. }
  144. $form = new FinanceExportForm();
  145. $result = $form->run(['condition' => $condition, 'params' => $params], Yii::t('ctx', 'memberEcoinAdjustmentListFileName')); // 会员余额调整列表
  146. if (!$result) {
  147. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  148. }
  149. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  150. }
  151. /**
  152. * 调整会员余额
  153. * @return mixed
  154. * @throws \yii\web\HttpException
  155. */
  156. public function actionChangeBalance() {
  157. if (Yii::$app->request->isPost) { // 申请变动会员余额成功
  158. return static::edit(ChangeBalanceForm::class, Yii::t('ctx', 'applicationChangeBalanceSucceeded'), 'changeAdd', ['changeAdd'], null, function ($formModel, $result) {
  159. // $userInfo = User::getBaseInfoFromRedis($result['USER_ID']);
  160. // $type = BalanceAudit::TYPE[$result['TYPE']]['label'];
  161. // Log::adminHandle('申请调整会员' . $userInfo['USER_NAME'] . '的' . $type . '余额,金额:' . $result['AMOUNT'], 1, $userInfo['ID'], $userInfo['USER_NAME'], $result['CREATE_REMARK']);
  162. });
  163. }
  164. }
  165. /**
  166. * 获取全部类型
  167. * @return mixed
  168. * @throws \yii\web\HttpException
  169. */
  170. public function actionChangeBalanceType(){
  171. $type = BalanceAudit::getBalanceAuditType();
  172. $dealTypes = DealType::getTypes();
  173. return static::notice(['type' => $type, 'dealTypes' => $dealTypes]);
  174. }
  175. /**
  176. * 调整会员余额信息
  177. * @return mixed
  178. * @throws \yii\base\Exception
  179. * @throws \yii\web\HttpException
  180. */
  181. public function actionBalanceAuditGet() {
  182. $id = Yii::$app->request->get('id');
  183. $balanceAudit = BalanceAudit::findOneAsArray('ID=:ID', [':ID' => $id]);
  184. if (!$balanceAudit) {
  185. return static::notice(Yii::t('ctx', 'dataNotExists'), 400);
  186. }
  187. $balanceAudit['BASE_INFO'] = Info::baseInfoWithBalance($balanceAudit['USER_ID']);
  188. return static::notice(['id' => $balanceAudit['ID'], 'baseInfo' => $balanceAudit['BASE_INFO'], 'type' => $balanceAudit['TYPE'], 'dealType' => $balanceAudit['DEAL_TYPE'], 'amount' => Tool::formatPrice($balanceAudit['AMOUNT']), 'remark' => $balanceAudit['CREATE_REMARK'], 'isShow' => $balanceAudit['REMARK_IS_SHOW']]);
  189. }
  190. /**
  191. * 修改调整会员余额数据
  192. * @return mixed
  193. * @throws \yii\db\Exception
  194. * @throws \yii\web\HttpException
  195. */
  196. public function actionBalanceAuditEdit() {
  197. $formModel = new ChangeBalanceForm();
  198. $formModel->scenario = 'edit';
  199. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  200. // $user = User::getBaseInfoFromRedis($result['USER_ID']);
  201. // Log::adminHandle('修改' . $user['USER_NAME'] . '调整会员余额录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  202. return static::notice(Yii::t('ctx', 'modificationAdjustmentMemberBalanceCompleted')); // 修改调整会员余额录入数据完成
  203. }
  204. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  205. }
  206. /**
  207. * 审核通过会员余额录入数据
  208. * @return mixed
  209. * @throws \yii\db\Exception
  210. * @throws \yii\web\HttpException
  211. */
  212. public function actionBalanceAuditPass() {
  213. $formModel = new ChangeBalanceForm();
  214. $formModel->scenario = 'pass';
  215. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->pass()) {
  216. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  217. // Log::adminHandle('审核通过' . $user['USER_NAME'] . '调整会员余额录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  218. return static::notice(Yii::t('ctx', 'reviewThroughMemberBalance')); // 审核通过会员余额完成
  219. }
  220. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  221. }
  222. /**
  223. * 审核会员余额
  224. * @return mixed
  225. * @throws \yii\db\Exception
  226. * @throws \yii\web\HttpException
  227. */
  228. public function actionBalanceAudit() {
  229. $formModel = new ChangeBalanceForm();
  230. $formModel->scenario = 'changeAudit';
  231. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeAudit()) {
  232. /*foreach ($result as $value) {
  233. $userName = Info::getUserNameByUserId($value['userId']);
  234. // Log::adminHandle('审核调整会员余额录入数据' . $userName . '发放' . $value['type'], 1, $value['userId'], $userName);
  235. }*/
  236. return static::notice(Yii::t('ctx', 'batchAuditMemberBalanceCompleted')); // 批量审核/审核拒绝会员余额完成
  237. }
  238. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  239. }
  240. /**
  241. * 删除审核会员余额信息
  242. * @return mixed
  243. * @throws \yii\db\Exception
  244. * @throws \yii\web\HttpException
  245. */
  246. public function actionBalanceAuditDelete() {
  247. $changeBalanceForm = new ChangeBalanceForm();
  248. $result = static::delete(BalanceAudit::class, function ($selected) use ($changeBalanceForm) {
  249. $changeBalanceForm->beforeDelete($selected);
  250. // Log::adminHandle('删除审核会员余额信息');
  251. }, function ($selected) use ($changeBalanceForm) {
  252. $changeBalanceForm->delete($selected);
  253. // Log::adminHandle('删除审核会员余额信息');
  254. }, true);
  255. return $result;
  256. }
  257. /**
  258. * 转账列表
  259. * @return mixed
  260. * @throws \yii\base\Exception
  261. * @throws \yii\web\HttpException
  262. */
  263. public function actionTransferList() {
  264. $filter = $this->filterCondition([
  265. 'TRANSFER_SN' => 'TRANSFER_SN',
  266. 'LAST_OUT_USER_NAME' => 'LAST_OUT_USER_NAME',
  267. 'LAST_OUT_REAL_NAME' => 'LAST_OUT_REAL_NAME',
  268. 'LAST_OUT_DEC_LV_NAME' => 'LAST_OUT_DEC_LV',
  269. // 'LAST_OUT_DEC_ROLE_NAME' => 'LAST_OUT_DEC_ROLE_ID',
  270. // 'OUT_WALLET' => 'OUT_WALLET',
  271. // 'LAST_OUT_SYSTEM_NAME' => 'LAST_OUT_SYSTEM_ID',
  272. 'LAST_IN_USER_NAME' => 'LAST_IN_USER_NAME',
  273. 'LAST_IN_REAL_NAME' => 'LAST_IN_REAL_NAME',
  274. 'LAST_IN_DEC_LV_NAME' => 'LAST_IN_DEC_LV',
  275. // 'IN_WALLET' => 'IN_WALLET',
  276. // 'LAST_IN_SYSTEM_NAME' => 'LAST_IN_SYSTEM_ID',
  277. 'ORI_AMOUNT' => 'ORI_AMOUNT',
  278. 'FEE' => 'FEE',
  279. 'AMOUNT' => 'AMOUNT',
  280. 'CREATED_AT' => 'CREATED_AT',
  281. 'PERIOD_NUM' => 'PERIOD_NUM',
  282. 'REMARK' => 'REMARK',
  283. //4047 国家筛选
  284. 'COUNTRY' => 'U.COUNTRY_ID',
  285. ]);
  286. $condition = $filter['condition'];
  287. $params = $filter['params'];
  288. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  289. if (!$isSuper) {
  290. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  291. $adminCountry = AdminCountry::getCountry($adminId);
  292. $quotedAdminCountry = array_map(function($item) {
  293. return "'" . addslashes($item) . "'";
  294. }, $adminCountry);
  295. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  296. }
  297. $listObj = new TransferList();
  298. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  299. return static::notice($data);
  300. }
  301. /**
  302. * 转账列表导出
  303. * @return mixed
  304. * @throws \yii\db\Exception
  305. * @throws \yii\web\HttpException
  306. */
  307. public function actionTransferListExport() {
  308. $filter = $this->filterCondition([
  309. 'TRANSFER_SN' => 'TRANSFER_SN',
  310. 'LAST_OUT_USER_NAME' => 'LAST_OUT_USER_NAME',
  311. 'LAST_OUT_REAL_NAME' => 'LAST_OUT_REAL_NAME',
  312. 'LAST_OUT_DEC_LV_NAME' => 'LAST_OUT_DEC_LV',
  313. 'LAST_OUT_DEC_ROLE_NAME' => 'LAST_OUT_DEC_ROLE_ID',
  314. 'OUT_WALLET' => 'OUT_WALLET',
  315. 'LAST_OUT_SYSTEM_NAME' => 'LAST_OUT_SYSTEM_ID',
  316. 'LAST_IN_USER_NAME' => 'LAST_IN_USER_NAME',
  317. 'LAST_IN_REAL_NAME' => 'LAST_IN_REAL_NAME',
  318. 'LAST_IN_DEC_LV_NAME' => 'LAST_IN_DEC_LV',
  319. 'IN_WALLET' => 'IN_WALLET',
  320. 'LAST_IN_SYSTEM_NAME' => 'LAST_IN_SYSTEM_ID',
  321. 'ORI_AMOUNT' => 'ORI_AMOUNT',
  322. 'FEE' => 'FEE',
  323. 'AMOUNT' => 'AMOUNT',
  324. 'CREATED_AT' => 'CREATED_AT',
  325. 'PERIOD_NUM' => 'PERIOD_NUM',
  326. 'REMARK' => 'REMARK',
  327. ]);
  328. $condition = $filter['condition'];
  329. $params = $filter['params'];
  330. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  331. if (!$isSuper) {
  332. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  333. $adminCountry = AdminCountry::getCountry($adminId);
  334. $quotedAdminCountry = array_map(function($item) {
  335. return "'" . addslashes($item) . "'";
  336. }, $adminCountry);
  337. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  338. }
  339. $form = new FinanceExportForm();
  340. $result = $form->run(['condition' => $condition, 'params' => $params], Yii::t('ctx', 'financeControllerTransferListExport')); // 转账列表
  341. if (!$result) {
  342. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  343. }
  344. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  345. }
  346. /**
  347. * 提现列表
  348. * @return mixed
  349. * @throws \yii\base\Exception
  350. * @throws \yii\web\HttpException
  351. */
  352. public function actionWithdraw() {
  353. $filter = $this->filterCondition([
  354. 'SN' => 'W.SN',
  355. 'WITHDRAW_PERIOD_NUM' => 'W.WITHDRAW_PERIOD_NUM',
  356. 'filterStatus' => 'W.AUDIT_STATUS',
  357. 'CREATED_AT' => 'W.CREATED_AT',
  358. 'PAID_AT' => 'W.PAID_AT',
  359. 'USER_NAME' => 'U.USER_NAME',
  360. 'REAL_AMOUNT' => 'W.REAL_AMOUNT',
  361. //4047新增 “会员姓名”、“国家”、“提现银行”、“手机号"
  362. 'USER_REAL_NAME' => 'U.REAL_NAME',
  363. 'COUNTRY_NAME' => 'U.COUNTRY_ID',
  364. 'OPEN_BANK' => 'U.OPEN_BANK',
  365. 'MOBILE' => 'U.MOBILE',
  366. ]);
  367. $condition = $filter['condition'];
  368. $params = $filter['params'];
  369. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  370. if (!$isSuper) {
  371. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  372. $adminCountry = AdminCountry::getCountry($adminId);
  373. $quotedAdminCountry = array_map(function($item) {
  374. return "'" . addslashes($item) . "'";
  375. }, $adminCountry);
  376. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  377. }
  378. $listObj = new WithdrawList();
  379. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  380. return static::notice($data);
  381. }
  382. /**
  383. * 后台新增提现
  384. * @return mixed
  385. * @throws \yii\web\HttpException
  386. */
  387. public function actionWithdrawAdd() {
  388. if (Yii::$app->request->isPost) {// 新增会员提现成功
  389. return parent::edit(WithdrawForm::class, Yii::t('ctx', 'addedMemberSuccessfullyWithdrewCash'), 'addByAdmin', ['add'], null, function ($form, $result) {
  390. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  391. // Log::adminHandle('申请为' . $user['USER_NAME'] . '提现' . $result['WITHDRAW_AMOUNT'], 1, $result['USER_ID'], $user['USER_NAME']);
  392. });
  393. }
  394. // 获取全部注册类型
  395. $regTypes = RegType::getTypes();
  396. return static::notice(['regTypes' => $regTypes]);
  397. }
  398. /**
  399. * 提现数据获取
  400. * @return mixed
  401. * @throws \yii\base\Exception
  402. * @throws \yii\web\HttpException
  403. */
  404. public function actionWithdrawGet() {
  405. $id = Yii::$app->request->get('id');
  406. $withdraw = Withdraw::findOneAsArray('ID=:ID', [':ID' => $id]);
  407. if (!$withdraw) {
  408. return static::notice(Yii::t('ctx', 'dataDoesNotExists'), 400); // 数据不存在
  409. }
  410. $withdraw['BASE_INFO'] = Info::baseInfoZh($withdraw['USER_ID']);
  411. $withdraw['PLAN_PAID_AT'] = $withdraw['PLAN_PAID_AT'] ? Date::convert($withdraw['PLAN_PAID_AT']) : null;
  412. return static::notice(['id' => $withdraw['ID'], 'baseInfo' => $withdraw['BASE_INFO'], 'amount' => Tool::formatPrice($withdraw['AMOUNT']), 'planPaidAt' => $withdraw['PLAN_PAID_AT'], 'remark' => $withdraw['REMARK']]);
  413. }
  414. /**
  415. * 修改提现
  416. * @return mixed
  417. * @throws \yii\db\Exception
  418. * @throws \yii\web\HttpException
  419. */
  420. public function actionWithdrawEdit() {
  421. $id = Yii::$app->request->get('id');
  422. if (Yii::$app->request->isPost) {
  423. $formModel = new WithdrawForm();
  424. $formModel->scenario = 'editByAdmin';
  425. $formModel->id = $id;
  426. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->editByAdmin()) {
  427. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  428. // Log::adminHandle('修改提现信息,ID为:' . $result['ID'], 1, $result['USER_ID'], $user['USER_NAME']);
  429. return static::notice(Yii::t('ctx', 'withdrawalInformationModifiedSuccessfully')); // 修改提现信息成功
  430. } else {
  431. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  432. }
  433. }
  434. return static::notice('Illegal request', 400); // 非法请求
  435. }
  436. /**
  437. * 改变状态
  438. * @return mixed
  439. * @throws \yii\base\Exception
  440. * @throws \yii\db\Exception
  441. * @throws \yii\web\HttpException
  442. */
  443. public function actionWithdrawStatus() {
  444. $id = Yii::$app->request->get('id');
  445. if (Yii::$app->request->isPost) {
  446. $formModel = new WithdrawForm();
  447. $formModel->scenario = 'statusByAdmin';
  448. $formModel->id = $id;
  449. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  450. foreach ($result['logs'] as $k => $value) {
  451. $userName = Info::getUserNameByUserId($k);
  452. // Log::adminHandle('为会员' . $userName . '的提现流水号为' . $value . '改变提现状态至' . Withdraw::STATUS_NAME[$result['status']], 1, $k, $userName);
  453. }
  454. return static::notice(Yii::t('ctx', 'statusSettingSucceeded')); // 状态设置成功
  455. } else {
  456. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  457. }
  458. }
  459. return static::notice(Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
  460. }
  461. /**
  462. * 提现明细导出到excel
  463. * @return mixed
  464. * @throws \yii\db\Exception
  465. * @throws \yii\web\HttpException
  466. */
  467. public function actionWithdrawExport() {
  468. $filter = $this->filterCondition([
  469. 'SN' => 'W.SN',
  470. 'CREATED_AT' => 'W.CREATED_AT',
  471. 'AUDIT_STATUS_NAME' => 'W.AUDIT_STATUS',
  472. 'USER_NAME' => 'U.USER_NAME',
  473. 'WITHDRAW_PERIOD_NUM' => 'W.WITHDRAW_PERIOD_NUM',
  474. 'REAL_AMOUNT' => 'W.REAL_AMOUNT'
  475. ]);
  476. // $selectedIds = \Yii::$app->request->get('selectedIds', []);
  477. // if ($selectedIds) {
  478. // $filter['condition'] .= " AND W.ID IN (" . implode(',', $selectedIds) . ")";
  479. // }
  480. if (isset($filter['request']['filterStatus'])) {
  481. $status = explode(',',$filter['request']['filterStatus']);
  482. $status = end($status);
  483. if (is_numeric($status)) {
  484. $filter['condition'] .= " AND W.AUDIT_STATUS = $status";
  485. }
  486. }
  487. if (isset($filter['request']['WITHDRAW_PERIOD_NUM'])) {
  488. $period = explode(',',$filter['request']['WITHDRAW_PERIOD_NUM']);
  489. $periodNum = isset($period[1]) ? $period[1] : '';
  490. if (is_numeric($periodNum)) {
  491. $filter['condition'] .= " AND W.WITHDRAW_PERIOD_NUM = $periodNum";
  492. }
  493. }
  494. $condition = $filter['condition'];
  495. $params = $filter['params'];
  496. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  497. if (!$isSuper) {
  498. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  499. $adminCountry = AdminCountry::getCountry($adminId);
  500. $quotedAdminCountry = array_map(function($item) {
  501. return "'" . addslashes($item) . "'";
  502. }, $adminCountry);
  503. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  504. }
  505. $form = new FinanceExportForm();
  506. $result = $form->run(['condition' => $condition, 'params' => $params], Yii::t('ctx', 'exportWithdrawApplyExcelName')); // 提现申请
  507. if (!$result) {
  508. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  509. }
  510. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  511. }
  512. /**
  513. * 分页导入excel文件到待导入数据的表中
  514. * @return mixed
  515. * @throws \yii\base\Exception
  516. * @throws \yii\web\HttpException
  517. */
  518. public function actionImportWithdrawsToExcelTable() {
  519. // 先上传到服务器文件
  520. if (\Yii::$app->request->isPost) {
  521. $excelImportId = Yii::$app->request->post('excelImportId');
  522. $rowCount = Yii::$app->request->post('rowCount');
  523. $startRow = Yii::$app->request->post('startRow');
  524. $limit = Yii::$app->request->post('limit', 1000);
  525. $errorMsg = '';
  526. try {
  527. $excel = new Excel();
  528. $result = $excel->pageImportDataFromExcel('withdrawPaidFalse', $excelImportId, $rowCount, $startRow, $limit);
  529. } catch (\Exception $e) {
  530. $result = false;
  531. $errorMsg = $e->getMessage();
  532. }
  533. // 还有数据
  534. if ($result === 1) {
  535. return static::notice(['finish' => false]);
  536. } elseif ($result === 0) {
  537. return static::notice(['finish' => true]);
  538. } else {
  539. return static::notice('Error:' . $errorMsg, 400);
  540. }
  541. }
  542. }
  543. /**
  544. * 分页把待导入表中的数据导入到真正的数据中
  545. * @return mixed
  546. * @throws \yii\base\Exception
  547. * @throws \yii\web\HttpException
  548. */
  549. public function actionImportWithdrawsPaidFalse() {
  550. if (\Yii::$app->request->isPost) {
  551. $excelImportId = Yii::$app->request->post('excelImportId');
  552. $offset = Yii::$app->request->post('offset');
  553. $limit = Yii::$app->request->post('limit', 1000);
  554. $errorMsg = '';
  555. try {
  556. $excel = new Excel();
  557. $result = $excel->pageImportDataFromExcelTable('withdrawPaidFalse', $excelImportId, $offset, $limit);
  558. } catch (\Exception $e) {
  559. $result = false;
  560. $errorMsg = $e->getMessage();
  561. }
  562. // 还有数据
  563. if ($result === 1) {
  564. return static::notice(['finish' => false]);
  565. } elseif ($result === 0) {
  566. return static::notice(['finish' => true]);
  567. } else {
  568. return static::notice('error:' . $errorMsg, 400);
  569. }
  570. }
  571. }
  572. /**
  573. * 发票管理
  574. * @return mixed
  575. * @throws \yii\base\Exception
  576. * @throws \yii\web\HttpException
  577. */
  578. public function actionInvoiceAudit() {
  579. $filter = $this->filterCondition([
  580. 'userIds' => 'UI.USER_ID',
  581. 'createdAt' => 'IA.CREATED_AT',
  582. 'regType' => 'IA.REG_TYPE',
  583. 'filterStatus' => 'IA.AUDIT_STATUS',
  584. 'INVOICE_CODE' => 'IA.INVOICE_CODE',
  585. 'INVOICE_NUM' => 'IA.INVOICE_NUM',
  586. 'INVOICE_DATE' => 'IA.INVOICE_DATE',
  587. 'AMOUNT' => 'IA.AMOUNT',
  588. 'SN' => 'W.SN',
  589. ]);
  590. $condition = $filter['condition'];
  591. $params = $filter['params'];
  592. $data = InvoiceAudit::lists($condition, $params, [
  593. 'select' => 'IA.*,W.SN WITHDRAW_SN,U.URL INVOICE_URL',
  594. 'orderBy' => 'IA.CREATED_AT DESC',
  595. 'from' => InvoiceAudit::tableName() . ' AS IA',
  596. 'join' => [
  597. ['LEFT JOIN', UserInfo::tableName() . ' AS UI', 'IA.USER_ID=UI.USER_ID'],
  598. ['LEFT JOIN', Uploads::tableName() . ' AS U', 'IA.UPLOAD_ID=U.ID'],
  599. ['LEFT JOIN', Withdraw::tableName() . ' AS W', 'IA.WITHDRAW_ID=W.ID'],
  600. ],
  601. ]);
  602. $auditStatus = array_column(Tool::paramConvert(\Yii::$app->params['auditStatus']), null, 'value');
  603. foreach ($data['list'] as $key => $value) {
  604. $data['list'][$key]['BASE_INFO'] = Info::baseInfoZh($value['USER_ID']);
  605. $data['list'][$key]['CREATE_ADMIN_NAME'] = Admin::getAdminNameById($value['CREATE_ADMIN']);
  606. $data['list'][$key]['AUDIT_ADMIN_NAME'] = Admin::getAdminNameById($value['AUDIT_ADMIN']);
  607. $data['list'][$key]['STATUS_NAME'] = $auditStatus[$value['AUDIT_STATUS']]['label'];
  608. }
  609. return static::notice($data);
  610. }
  611. /**
  612. * 发票录入
  613. * @return mixed
  614. * @throws \yii\web\HttpException
  615. */
  616. public function actionInvoiceAuditAdd() {
  617. if (Yii::$app->request->isPost) {
  618. return parent::edit(InvoiceAuditForm::class, Yii::t('ctx', 'invoiceEnteredSuccessfully'), 'addByAdmin', ['addByAdmin'], null, function ($form, $result) {
  619. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  620. // Log::adminHandle('申请为' . $user['USER_NAME'] . '发票录入', 1, $result['USER_ID'], $user['USER_NAME']);
  621. });
  622. }
  623. // 获取全部注册类型
  624. $regTypes = RegType::getTypes();
  625. return static::notice(['regTypes' => $regTypes]);
  626. }
  627. /**
  628. * 发票信息获取
  629. * @return mixed
  630. * @throws \yii\base\Exception
  631. * @throws \yii\web\HttpException
  632. */
  633. public function actionInvoiceAuditGet() {
  634. $id = Yii::$app->request->get('id');
  635. $invoiceAudit = InvoiceAudit::findOneAsArray('ID=:ID AND AUDIT_STATUS=:AUDIT_STATUS', [':ID' => $id, ':AUDIT_STATUS' => \Yii::$app->params['auditStatus']['un']['value']]);
  636. if (!$invoiceAudit) {
  637. return static::notice(['id' => null, 'withdrawId' => null, 'withdrawSn' => null, 'invoiceCode' => null, 'invoiceNum' => null, 'invoiceDate' => null, 'amount' => null, 'taxRate' => null, 'purchaserName' => null, 'purchaserRegisterNum' => null, 'purchaserAddress' => null, 'purchaserBank' => null, 'sellerName' => null, 'sellerRegisterNum' => null, 'sellerAddress' => null, 'sellerBank' => null, 'itemName' => null, 'invoiceRemark' => null, 'createRemark' => null]);
  638. }
  639. $invoiceAudit['BASE_INFO'] = Info::baseInfoZh($invoiceAudit['USER_ID']);
  640. $invoiceAudit['INVOICE_DATE'] = $invoiceAudit['INVOICE_DATE'] ? (Date::validator(str_replace(['年', '月', '日'], ['-', '-', ''], $invoiceAudit['INVOICE_DATE']))?Date::convert(str_replace(['年', '月', '日'], ['-', '-', ''], $invoiceAudit['INVOICE_DATE'])):null) : null;
  641. $withdraw = Withdraw::findOneAsArray('ID=:ID', [':ID' => $invoiceAudit['WITHDRAW_ID']], 'ID,SN');
  642. return static::notice(['id' => $invoiceAudit['ID'], 'withdrawId' => $withdraw['ID'], 'withdrawSn' => $withdraw['SN'], 'invoiceCode' => $invoiceAudit['INVOICE_CODE'], 'invoiceNum' => $invoiceAudit['INVOICE_NUM'], 'invoiceDate' => $invoiceAudit['INVOICE_DATE'], 'amount' => Tool::formatPrice($invoiceAudit['AMOUNT']), 'taxRate' => $invoiceAudit['TAX_RATE'], 'purchaserName' => $invoiceAudit['PURCHASER_NAME'], 'purchaserRegisterNum' => $invoiceAudit['PURCHASER_REGISTER_NUM'], 'purchaserAddress' => $invoiceAudit['PURCHASER_ADDRESS'], 'purchaserBank' => $invoiceAudit['PURCHASER_BANK'], 'sellerName' => $invoiceAudit['SELLER_NAME'], 'sellerRegisterNum' => $invoiceAudit['SELLER_REGISTER_NUM'], 'sellerAddress' => $invoiceAudit['SELLER_ADDRESS'], 'sellerBank' => $invoiceAudit['SELLER_BANK'], 'itemName' => $invoiceAudit['ITEM_NAME'], 'invoiceRemark' => $invoiceAudit['INVOICE_REMARK'], 'createRemark' => $invoiceAudit['CREATE_REMARK']]);
  643. }
  644. /**
  645. * 发票信息修改
  646. * @return mixed
  647. * @throws \yii\db\Exception
  648. * @throws \yii\web\HttpException
  649. */
  650. public function actionInvoiceAuditEdit() {
  651. $formModel = new InvoiceAuditForm();
  652. $formModel->scenario = 'editByAdmin';
  653. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->editByAdmin()) {
  654. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  655. // Log::adminHandle('修改' . $user['USER_NAME'] . '发票录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  656. return static::notice(Yii::t('ctx', 'modifyInvoiceEntryCompleted'));
  657. }
  658. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  659. }
  660. /**
  661. * 发票信息审核
  662. * @return mixed
  663. * @throws \yii\db\Exception
  664. * @throws \yii\web\HttpException
  665. */
  666. public function actionInvoiceAuditAudit() {
  667. $formModel = new InvoiceAuditForm();
  668. $formModel->scenario = 'audit';
  669. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->audit()) {
  670. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  671. // Log::adminHandle('审核' . $user['USER_NAME'] . '发票录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  672. return static::notice(Yii::t('ctx', 'reviewInvoiceDataCompleted'));
  673. }
  674. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  675. }
  676. /**
  677. * 发票信息删除
  678. * @return mixed
  679. * @throws \yii\db\Exception
  680. * @throws \yii\web\HttpException
  681. */
  682. public function actionInvoiceAuditDelete() {
  683. $result = static::delete(InvoiceAudit::class, null, function ($selected) {
  684. InvoiceAuditForm::delete($selected);
  685. // Log::adminHandle('删除发票信息');
  686. }, true);
  687. return $result;
  688. }
  689. /**
  690. * 调整会员业绩审核列表
  691. * @return mixed
  692. * @throws \yii\base\Exception
  693. * @throws \yii\web\HttpException
  694. */
  695. public function actionPerfAuditList() {
  696. $filter = $this->filterCondition([
  697. 'userIds' => 'UI.USER_ID',
  698. 'filterStatus' => 'PA.AUDIT_STATUS',
  699. 'SYSTEM_NAME' => 'UI.SYSTEM_ID',
  700. 'PV_1L' => 'PA.PV_1L',
  701. 'SURPLUS_1L' => 'PA.SURPLUS_1L',
  702. 'PV_2L' => 'PA.PV_2L',
  703. 'SURPLUS_2L' => 'PA.SURPLUS_2L',
  704. 'PV_3L' => 'PA.PV_3L',
  705. 'SURPLUS_3L' => 'PA.SURPLUS_3L',
  706. 'PV_4L' => 'PA.PV_4L',
  707. 'SURPLUS_4L' => 'PA.SURPLUS_4L',
  708. 'PV_5L' => 'PA.PV_5L',
  709. 'SURPLUS_5L' => 'PA.SURPLUS_5L',
  710. 'SURPLUS_LS' => 'PA.SURPLUS_LS',
  711. 'PERF_TYPE_NAME' => 'PA.PERF_TYPE',
  712. 'PERF_LOCATION_NAME' => 'PA.PERF_LOCATION',
  713. 'PERF_BEFORE' => 'PA.PERF_BEFORE',
  714. 'AMOUNT' => 'PA.AMOUNT',
  715. 'PERF_AFTER' => 'PA.PERF_AFTER',
  716. 'CREATED_AT' => 'PA.CREATED_AT',
  717. 'AUDITED_AT' => 'PA.AUDITED_AT',
  718. 'REMARK' => 'PA.REMARK',
  719. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  720. 'AUDIT_ADMIN_NAME' => 'ADMU.ADMIN_NAME',
  721. ]);
  722. $condition = $filter['condition'];
  723. $params = $filter['params'];
  724. $listObj = new PerfAuditList();
  725. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  726. return static::notice($data);
  727. }
  728. /**
  729. * 会员业绩调整列表导出
  730. * @return mixed
  731. * @throws \yii\db\Exception
  732. * @throws \yii\web\HttpException
  733. */
  734. public function actionPerfAuditListExport() {
  735. $filter = $this->filterCondition([
  736. 'userIds' => 'UI.USER_ID',
  737. 'filterStatus' => 'PA.AUDIT_STATUS',
  738. 'SYSTEM_NAME' => 'UI.SYSTEM_ID',
  739. 'PV_1L' => 'PA.PV_1L',
  740. 'SURPLUS_1L' => 'PA.SURPLUS_1L',
  741. 'PV_2L' => 'PA.PV_2L',
  742. 'SURPLUS_2L' => 'PA.SURPLUS_2L',
  743. 'PV_3L' => 'PA.PV_3L',
  744. 'SURPLUS_3L' => 'PA.SURPLUS_3L',
  745. 'PV_4L' => 'PA.PV_4L',
  746. 'SURPLUS_4L' => 'PA.SURPLUS_4L',
  747. 'PV_5L' => 'PA.PV_5L',
  748. 'SURPLUS_5L' => 'PA.SURPLUS_5L',
  749. 'SURPLUS_LS' => 'PA.SURPLUS_LS',
  750. 'PERF_TYPE_NAME' => 'PA.PERF_TYPE',
  751. 'PERF_LOCATION_NAME' => 'PA.PERF_LOCATION',
  752. 'PERF_BEFORE' => 'PA.PERF_BEFORE',
  753. 'AMOUNT' => 'PA.AMOUNT',
  754. 'PERF_AFTER' => 'PA.PERF_AFTER',
  755. 'CREATED_AT' => 'PA.CREATED_AT',
  756. 'AUDITED_AT' => 'PA.AUDITED_AT',
  757. 'REMARK' => 'PA.REMARK',
  758. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  759. 'AUDIT_ADMIN_NAME' => 'ADMU.ADMIN_NAME',
  760. ]);
  761. $form = new FinanceExportForm();
  762. $result = $form->run($filter, Yii::t('ctx', 'memberPerformanceAdjustmentList'));
  763. if (!$result) {
  764. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  765. }
  766. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  767. }
  768. /**
  769. * 申请调整会员业绩
  770. * @return mixed
  771. * @throws \yii\web\HttpException
  772. */
  773. public function actionPerfApply() {
  774. if (\Yii::$app->request->isPost) { // 申请调整会员业绩成功
  775. return static::edit(ChangePerfForm::class, Yii::t('ctx', 'applicationAdjustMemberPerfSuccess'), 'add', ['add'], null, function ($formModel, $result) {
  776. // 添加操作日志
  777. // Log::adminHandle('申请调整会员' . $formModel->userName . '的' . $formModel->location . '区业绩,调整额度为:' . $formModel->amount);
  778. });
  779. }
  780. $periodNum = Period::sentMaxPeriodNum();
  781. return static::notice(['periodNum' => $periodNum]);
  782. }
  783. /**
  784. * 获取调整会员的业绩
  785. * @return mixed
  786. * @throws \yii\web\HttpException
  787. */
  788. public function actionPerfApplyGet() {
  789. $periodNum = Period::sentMaxPeriodNum();
  790. if (Period::find()->where('IS_SENT=:IS_SENT AND PERIOD_NUM>=:START_PERIOD_NUM AND PERIOD_NUM<=:END_PERIOD_NUM', [':IS_SENT' => Period::SEND_FINISH, ':START_PERIOD_NUM' => $periodNum + 1, ':END_PERIOD_NUM' => $periodNum + 1])->count() == 1) {
  791. // return static::notice('下一期【' . ($periodNum + 1) . '】已挂网,该期无法调整', 400);
  792. return static::notice(Yii::t('ctx', 'nextPeriodConnectedNetCannotAdjusted',[
  793. 'periodNum' => $periodNum + 1
  794. ]), 400);
  795. }
  796. $userName = \Yii::$app->request->get('userName');
  797. if (!$userId = Info::getUserIdByUserName($userName)) {
  798. return static::notice(Yii::t('ctx', 'memberDoesNotExist'), 400); // 会员不存在
  799. }
  800. $perf = PerfAudit::getUserPerfAndPerfPeriod($userId, $periodNum);
  801. return static::notice(array_merge(['REAL_NAME' => Info::getUserRealNameByUserId($userId)], $perf));
  802. }
  803. /**
  804. * 获取会员业绩审核信息
  805. * @return mixed
  806. * @throws \yii\web\HttpException
  807. */
  808. public function actionPerfAuditGet() {
  809. $id = Yii::$app->request->get('id');
  810. $perfAudit = PerfAudit::findOneAsArray('ID=:ID', [':ID' => $id]);
  811. if (!$perfAudit) {
  812. return static::notice(Yii::t('ctx', 'dataDoesNotExists'), 400); // 数据不存在
  813. }
  814. $perf = PerfAudit::getUserPerfAndPerfPeriod($perfAudit['USER_ID'], $perfAudit['PERIOD_NUM']);
  815. return static::notice(['userInfo'=>array_merge(['USER_NAME' => Info::getUserNameByUserId($perfAudit['USER_ID']),'REAL_NAME' => Info::getUserRealNameByUserId($perfAudit['USER_ID'])], $perf),'perfAudit'=>['periodNum'=>$perfAudit['PERIOD_NUM'],'perfType'=>$perfAudit['PERF_TYPE'],'location'=>$perfAudit['PERF_LOCATION'],'amount'=>Tool::formatPrice($perfAudit['AMOUNT']),'remark'=>$perfAudit['REMARK'],'id'=>$perfAudit['ID']]]);
  816. }
  817. /**
  818. * 审核通过会员业绩录入数据
  819. * @return mixed
  820. * @throws \yii\db\Exception
  821. * @throws \yii\web\HttpException
  822. */
  823. public function actionPerfAuditPass() {
  824. $formModel = new ChangePerfForm();
  825. $formModel->scenario = 'pass';
  826. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->pass()) {
  827. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  828. // Log::adminHandle('审核通过' . $user['USER_NAME'] . '调整会员业绩录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  829. return static::notice(Yii::t('ctx', 'passReviewAdjustPerfSuccess'));
  830. }
  831. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  832. }
  833. /**
  834. * 审核会员业绩
  835. * @return mixed
  836. * @throws \yii\db\Exception
  837. * @throws \yii\web\HttpException
  838. */
  839. public function actionPerfAudit() {
  840. $formModel = new ChangePerfForm();
  841. $formModel->scenario = 'changeAudit';
  842. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeAudit()) {
  843. foreach ($result as $value) {
  844. $userName = Info::getUserNameByUserId($value['userId']);
  845. // Log::adminHandle('审核调整会员业绩录入数据' . $userName, 1, $value['userId'], $userName);
  846. }
  847. return static::notice(Yii::t('ctx', 'batchReviewMemberPerfCompletion'));
  848. }
  849. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  850. }
  851. /**
  852. * 删除审核会员业绩信息
  853. * @return mixed
  854. * @throws \yii\db\Exception
  855. * @throws \yii\web\HttpException
  856. */
  857. public function actionPerfAuditDelete() {
  858. $changePerfForm = new ChangePerfForm();
  859. $result = static::delete(PerfAudit::class, function ($selected) use ($changePerfForm) {
  860. $changePerfForm->beforeDelete($selected);
  861. // Log::adminHandle('删除审核会员余额信息');
  862. }, function ($selected) use ($changePerfForm) {
  863. $changePerfForm->delete($selected);
  864. // Log::adminHandle('删除审核会员余额信息');
  865. }, true);
  866. return $result;
  867. }
  868. /**
  869. * 交易类型管理
  870. * @return mixed
  871. * @throws \yii\web\HttpException
  872. */
  873. public function actionDealType() {
  874. $condition = '';
  875. $params = [];
  876. $data = DealType::lists($condition, $params, [
  877. 'orderBy' => 'DT.IS_PRESET ASC,DT.SORT_ORDER DESC',
  878. 'from' => DealType::tableName() . ' AS DT',
  879. ]);
  880. foreach ($data['list'] as $key => $value) {
  881. $data['list'][$key]['CREATE_ADMIN_NAME'] = Admin::getAdminNameById($value['CREATE_ADMIN']);
  882. $data['list'][$key]['UPDATE_ADMIN_NAME'] = Admin::getAdminNameById($value['UPDATE_ADMIN']);
  883. }
  884. return static::notice($data);
  885. }
  886. /**
  887. * 交易类型录入
  888. * @return mixed
  889. * @throws \yii\web\HttpException
  890. */
  891. public function actionDealTypeAdd() {
  892. if (Yii::$app->request->isPost) {
  893. return parent::edit(DealTypeForm::class, Yii::t('ctx', 'transactionTypeAddSuccess'), 'add', ['add'], null, function ($form, $result) {
  894. // Log::adminHandle('交易类型录入');
  895. });
  896. }
  897. }
  898. /**
  899. * 交易类型获取
  900. * @return mixed
  901. * @throws \yii\web\HttpException
  902. */
  903. public function actionDealTypeGet() {
  904. $id = Yii::$app->request->get('id');
  905. $dealType = DealType::findOneAsArray('ID=:ID', [':ID' => $id]);
  906. if (!$dealType) {
  907. return static::notice(Yii::t('ctx', 'dataDoesNotExists'), 400); // 数据不存在
  908. }
  909. return static::notice(['id' => $dealType['ID'], 'typeName' => $dealType['TYPE_NAME'], 'isEnable' => $dealType['IS_ENABLE'] ? true : false, 'isPreset' => $dealType['IS_PRESET'] ? true : false, 'createRemark' => $dealType['CREATE_REMARK'], 'sort' => $dealType['SORT_ORDER']]);
  910. }
  911. /**
  912. * 交易类型修改
  913. * @return mixed
  914. * @throws \yii\db\Exception
  915. * @throws \yii\web\HttpException
  916. */
  917. public function actionDealTypeEdit() {
  918. $formModel = new DealTypeForm();
  919. $formModel->scenario = 'edit';
  920. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  921. // Log::adminHandle('修改交易类型');
  922. return static::notice(Yii::t('ctx', 'modifyTransactionTypeCompleted'));
  923. }
  924. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  925. }
  926. /**
  927. * 交易类型删除
  928. * @return mixed
  929. * @throws \yii\db\Exception
  930. * @throws \yii\web\HttpException
  931. */
  932. public function actionDealTypeDelete() {
  933. return static::notice(Yii::t('ctx', 'unableDelete'), 400);
  934. $result = static::delete(DealType::class, null, function ($selected) {
  935. DealTypeForm::delete($selected);
  936. // Log::adminHandle('删除交易类型');
  937. }, true);
  938. return $result;
  939. }
  940. /**
  941. * 分页导入excel文件到待导入数据的表中
  942. * @return mixed
  943. * @throws \yii\base\Exception
  944. * @throws \yii\web\HttpException
  945. */
  946. public function actionImportChangeBalanceToExcelTable() {
  947. // 先上传到服务器文件
  948. if (\Yii::$app->request->isPost) {
  949. $excelImportId = Yii::$app->request->post('excelImportId');
  950. $rowCount = Yii::$app->request->post('rowCount');
  951. $startRow = Yii::$app->request->post('startRow');
  952. $limit = Yii::$app->request->post('limit', 1000);
  953. $errorMsg = '';
  954. try {
  955. $excel = new Excel();
  956. $result = $excel->pageImportDataFromExcel('changeBalance', $excelImportId, $rowCount, $startRow, $limit);
  957. } catch (\Exception $e) {
  958. $result = false;
  959. $errorMsg = $e->getMessage();
  960. }
  961. // 还有数据
  962. if ($result === 1) {
  963. return static::notice(['finish' => false]);
  964. } elseif ($result === 0) {
  965. return static::notice(['finish' => true]);
  966. } else {
  967. return static::notice($errorMsg, 400);
  968. }
  969. }
  970. }
  971. /**
  972. * 分页把待导入表中的数据导入到真正的数据中
  973. * @return mixed
  974. * @throws \yii\base\Exception
  975. * @throws \yii\web\HttpException
  976. */
  977. public function actionImportChangeBalance() {
  978. if (\Yii::$app->request->isPost) {
  979. $excelImportId = Yii::$app->request->post('excelImportId');
  980. $offset = Yii::$app->request->post('offset');
  981. $limit = Yii::$app->request->post('limit', 1000);
  982. $errorMsg = '';
  983. try {
  984. $excel = new Excel();
  985. $result = $excel->pageImportDataFromExcelTable('changeBalance', $excelImportId, $offset, $limit);
  986. } catch (\Exception $e) {
  987. $result = false;
  988. $errorMsg = $e->getMessage();
  989. }
  990. // 还有数据
  991. if ($result === 1) {
  992. return static::notice(['finish' => false]);
  993. } elseif ($result === 0) {
  994. return static::notice(['finish' => true]);
  995. } else {
  996. return static::notice($errorMsg, 400);
  997. }
  998. }
  999. }
  1000. /**
  1001. * 历史奖金余额
  1002. * @return mixed
  1003. * @throws \yii\base\Exception
  1004. * @throws \yii\web\HttpException
  1005. */
  1006. public function actionHistoryBonus() {
  1007. $filter = $this->filterCondition([
  1008. 'USER_NAME' => 'USER_NAME',
  1009. 'REAL_NAME' => 'REAL_NAME',
  1010. 'DEC_LV_NAME' => 'DEC_LV',
  1011. 'EMP_LV_NAME' => 'EMP_LV',
  1012. 'IS_DEC' => 'IS_DEC',
  1013. // 'DEC_ROLE_NAME' => 'DEC_ROLE_ID',
  1014. 'SYSTEM_NAME' => 'SYSTEM_NAME',
  1015. 'BONUS' => 'BONUS',
  1016. // 'CF' => 'CF',
  1017. // 'LX' => 'LX',
  1018. 'WITHDRAW' => 'WITHDRAW',
  1019. // 'WITHDRAW_TAX' => 'WITHDRAW_TAX',
  1020. // 'WITHDRAW_DEDUCT' => 'WITHDRAW_DEDUCT',
  1021. 'WITHDRAW_REAL' => 'WITHDRAW_REAL',
  1022. 'WITHDRAW_FAIL' => 'WITHDRAW_FAIL',
  1023. 'USER_STATUS_NAME' => 'USER_STATUS',
  1024. 'USER_STATUS_AT' => 'USER_STATUS_AT',
  1025. // 'HIGHEST_EMP_LV_NAME' => 'HIGHEST_EMP_LV',
  1026. 'PERIOD_AT' => 'PERIOD_AT',
  1027. // 'DEC_DEC_ROLE_NAME' => 'DEC_DEC_ROLE_ID',
  1028. 'DEC_USER_NAME' => 'DEC_USER_NAME',
  1029. 'DEC_REAL_NAME' => 'DEC_REAL_NAME',
  1030. 'MOBILE' => 'MOBILE',
  1031. 'TEL' => 'TEL',
  1032. 'AREA' => [
  1033. 'FIELD' => ['PROVINCE', 'CITY', 'COUNTY'],
  1034. 'BIND' => ['PROVINCE', 'CITY', 'COUNTY'],
  1035. ],
  1036. // 'SUB_COM_NAME' => 'SUB_COM_ID',
  1037. // 'IS_DIRECT_SELLER' => 'IS_DIRECT_SELLER',
  1038. 'BACKUP_AT' => 'BACKUP_AT',
  1039. ]);
  1040. $condition = $filter['condition'];
  1041. $params = $filter['params'];
  1042. $listObj = new HistoryBonusList();
  1043. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  1044. return static::notice($data);
  1045. }
  1046. /**
  1047. * 历史奖金余额导出
  1048. * @return mixed
  1049. * @throws \yii\db\Exception
  1050. * @throws \yii\web\HttpException
  1051. */
  1052. public function actionHistoryBonusExport() {
  1053. $filter = $this->filterCondition([
  1054. 'USER_NAME' => 'USER_NAME',
  1055. 'REAL_NAME' => 'REAL_NAME',
  1056. 'DEC_LV_NAME' => 'DEC_LV',
  1057. 'EMP_LV_NAME' => 'EMP_LV',
  1058. 'IS_DEC' => 'IS_DEC',
  1059. 'DEC_ROLE_NAME' => 'DEC_ROLE_ID',
  1060. 'SYSTEM_NAME' => 'SYSTEM_NAME',
  1061. 'BONUS' => 'BONUS',
  1062. 'CF' => 'CF',
  1063. 'LX' => 'LX',
  1064. 'WITHDRAW' => 'WITHDRAW',
  1065. 'WITHDRAW_TAX' => 'WITHDRAW_TAX',
  1066. 'WITHDRAW_DEDUCT' => 'WITHDRAW_DEDUCT',
  1067. 'WITHDRAW_REAL' => 'WITHDRAW_REAL',
  1068. 'WITHDRAW_FAIL' => 'WITHDRAW_FAIL',
  1069. 'USER_STATUS_NAME' => 'USER_STATUS',
  1070. 'USER_STATUS_AT' => 'USER_STATUS_AT',
  1071. 'HIGHEST_EMP_LV_NAME' => 'HIGHEST_EMP_LV',
  1072. 'PERIOD_AT' => 'PERIOD_AT',
  1073. 'DEC_DEC_ROLE_NAME' => 'DEC_DEC_ROLE_ID',
  1074. 'DEC_USER_NAME' => 'DEC_USER_NAME',
  1075. 'DEC_REAL_NAME' => 'DEC_REAL_NAME',
  1076. 'MOBILE' => 'MOBILE',
  1077. 'TEL' => 'TEL',
  1078. 'AREA' => [
  1079. 'FIELD' => ['PROVINCE', 'CITY', 'COUNTY'],
  1080. 'BIND' => ['PROVINCE', 'CITY', 'COUNTY'],
  1081. ],
  1082. 'SUB_COM_NAME' => 'SUB_COM_ID',
  1083. 'IS_DIRECT_SELLER' => 'IS_DIRECT_SELLER',
  1084. 'BACKUP_AT' => 'BACKUP_AT',
  1085. ]);
  1086. $form = new FinanceExportForm();
  1087. $result = $form->run($filter, '历史奖金余额');
  1088. if (!$result) {
  1089. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1090. }
  1091. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1092. }
  1093. /**
  1094. * 充值列表
  1095. * @return mixed
  1096. * @throws \yii\base\Exception
  1097. * @throws \yii\web\HttpException
  1098. */
  1099. public function actionRecharge()
  1100. {
  1101. $filter = $this->filterCondition([
  1102. 'SN' => 'R.SN',
  1103. 'USER_NAME' => 'UI.USER_NAME',
  1104. 'AMOUNT' => 'R.AMOUNT',
  1105. 'AUDIT_STATUS' => 'R.AUDIT_STATUS',
  1106. 'BANK_NO' => 'R.BANK_NO',
  1107. 'CREATED_AT' => 'R.CREATED_AT',
  1108. ]);
  1109. $condition = $filter['condition'];
  1110. $params = $filter['params'];
  1111. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  1112. if (!$isSuper) {
  1113. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  1114. $adminCountry = AdminCountry::getCountry($adminId);
  1115. $quotedAdminCountry = array_map(function($item) {
  1116. return "'" . addslashes($item) . "'";
  1117. }, $adminCountry);
  1118. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  1119. }
  1120. $listObj = new RechargeList();
  1121. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  1122. return static::notice($data);
  1123. }
  1124. /**
  1125. * 提交充值申请
  1126. * @return mixed
  1127. * @throws \yii\db\Exception
  1128. * @throws \yii\web\HttpException
  1129. */
  1130. public function actionRechargeType() {
  1131. if (\Yii::$app->request->isPost) {
  1132. $formModel = new RechargeForm();
  1133. $formModel->scenario = 'updateByAdmin';
  1134. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->updateType()) {
  1135. return static::notice(Yii::t('app', 'successfully'));
  1136. } else {
  1137. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  1138. }
  1139. }
  1140. return static::notice(['type'=>['Cash', 'Credit Card', 'Direct Banking']]);
  1141. }
  1142. /**
  1143. * 充值导出
  1144. * @return mixed
  1145. * @throws \yii\db\Exception
  1146. * @throws \yii\web\HttpException
  1147. */
  1148. public function actionRechargeExport() {
  1149. $filter = $this->filterCondition([
  1150. 'SN' => 'R.SN',
  1151. 'USER_NAME' => 'UI.USER_NAME',
  1152. 'AMOUNT' => 'R.AMOUNT',
  1153. 'AUDIT_STATUS' => 'R.AUDIT_STATUS',
  1154. 'BANK_NO' => 'R.BANK_NO',
  1155. 'CREATED_AT' => 'R.CREATED_AT',
  1156. ]);
  1157. $condition = $filter['condition'];
  1158. $params = $filter['params'];
  1159. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  1160. if (!$isSuper) {
  1161. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  1162. $adminCountry = AdminCountry::getCountry($adminId);
  1163. $quotedAdminCountry = array_map(function($item) {
  1164. return "'" . addslashes($item) . "'";
  1165. }, $adminCountry);
  1166. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  1167. }
  1168. $form = new FinanceExportForm();
  1169. $result = $form->run(['condition' => $condition, 'params' => $params], 'Recharge'); // 充值申请
  1170. if (!$result) {
  1171. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1172. }
  1173. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1174. }
  1175. /**
  1176. * 改变充值状态
  1177. * @return mixed
  1178. * @throws \yii\base\Exception
  1179. * @throws \yii\db\Exception
  1180. * @throws \yii\web\HttpException
  1181. */
  1182. public function actionRechargeStatus() {
  1183. $id = Yii::$app->request->get('id');
  1184. if (Yii::$app->request->isPost) {
  1185. $formModel = new RechargeForm();
  1186. $formModel->scenario = 'statusByAdmin';
  1187. //$formModel->id = $id;
  1188. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  1189. foreach ($result['logs'] as $k => $value) {
  1190. $userName = Info::getUserNameByUserId($k);
  1191. // Log::adminHandle('为会员' . $userName . '的充值流水号为' . $value . '改变充值状态至' . Recharge::STATUS_NAME[$result['status']], 1, $k, $userName);
  1192. }
  1193. return static::notice(Yii::t('ctx', 'statusSettingSucceeded')); // 状态设置成功
  1194. } else {
  1195. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  1196. }
  1197. }
  1198. // 所有开户行
  1199. $statusArray = [
  1200. 2=>Yii::t('ctx', 'backendApiControllersFinaceRechargeStatusApprove'),
  1201. 3=>Yii::t('ctx', 'backendApiControllersFinaceRechargeStatusReject'),
  1202. ]; // 2=>'审核通过',3=>'审核拒绝'
  1203. return static::notice(['statusArray' => $statusArray]);
  1204. }
  1205. /**
  1206. * 连点操作校验码获取
  1207. * @return mixed
  1208. * @throws \yii\web\HttpException
  1209. */
  1210. public function actionMultPoint() {
  1211. $verifyCode = $this->_random(8,1);
  1212. $adminId = \Yii::$app->user->id;
  1213. if (\Yii::$app->request->isPost) {
  1214. $opType = Yii::$app->request->post('opType');
  1215. if($opType==1){
  1216. $redisName = 'balanceCode';
  1217. }elseif ($opType==2){
  1218. $redisName = 'withdrawAudit';
  1219. }
  1220. }
  1221. \Yii::$app->redis->set($redisName.'_'.$adminId,$verifyCode);
  1222. return static::notice([$redisName => $verifyCode]);
  1223. }
  1224. /**
  1225. * 生成随机数
  1226. * @param $length
  1227. * @param int $numeric
  1228. * @return string
  1229. */
  1230. private function _random($length, $numeric = 0) {
  1231. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  1232. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  1233. $hash = '';
  1234. $max = strlen($seed) - 1;
  1235. for ($i = 0; $i < $length; $i++) {
  1236. $hash .= $seed[mt_rand(0, $max)];
  1237. }
  1238. return $hash;
  1239. }
  1240. }