FinanceController.php 50 KB

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