FinanceController.php 49 KB

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