FinanceController.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  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('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  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('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  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. 'AMOUNT' => 'W.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. ]);
  436. // $selectedIds = \Yii::$app->request->get('selectedIds', []);
  437. // if ($selectedIds) {
  438. // $filter['condition'] .= " AND W.ID IN (" . implode(',', $selectedIds) . ")";
  439. // }
  440. if (isset($filter['request']['filterStatus'])) {
  441. $status = explode(',',$filter['request']['filterStatus']);
  442. $status = end($status);
  443. if (is_numeric($status)) {
  444. $filter['condition'] .= " AND W.AUDIT_STATUS = $status";
  445. }
  446. }
  447. if (isset($filter['request']['WITHDRAW_PERIOD_NUM'])) {
  448. $period = explode(',',$filter['request']['WITHDRAW_PERIOD_NUM']);
  449. $periodNum = isset($period[1]) ? $period[1] : '';
  450. if (is_numeric($periodNum)) {
  451. $filter['condition'] .= " AND W.WITHDRAW_PERIOD_NUM = $periodNum";
  452. }
  453. }
  454. $form = new FinanceExportForm();
  455. $result = $form->run($filter, 'Withdraw_Apply'); // 提现申请
  456. if (!$result) {
  457. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  458. }
  459. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  460. }
  461. /**
  462. * 分页导入excel文件到待导入数据的表中
  463. * @return mixed
  464. * @throws \yii\base\Exception
  465. * @throws \yii\web\HttpException
  466. */
  467. public function actionImportWithdrawsToExcelTable() {
  468. // 先上传到服务器文件
  469. if (\Yii::$app->request->isPost) {
  470. $excelImportId = Yii::$app->request->post('excelImportId');
  471. $rowCount = Yii::$app->request->post('rowCount');
  472. $startRow = Yii::$app->request->post('startRow');
  473. $limit = Yii::$app->request->post('limit', 1000);
  474. $errorMsg = '';
  475. try {
  476. $excel = new Excel();
  477. $result = $excel->pageImportDataFromExcel('withdrawPaidFalse', $excelImportId, $rowCount, $startRow, $limit);
  478. } catch (\Exception $e) {
  479. $result = false;
  480. $errorMsg = $e->getMessage();
  481. }
  482. // 还有数据
  483. if ($result === 1) {
  484. return static::notice(['finish' => false]);
  485. } elseif ($result === 0) {
  486. return static::notice(['finish' => true]);
  487. } else {
  488. return static::notice('Error:' . $errorMsg, 400);
  489. }
  490. }
  491. }
  492. /**
  493. * 分页把待导入表中的数据导入到真正的数据中
  494. * @return mixed
  495. * @throws \yii\base\Exception
  496. * @throws \yii\web\HttpException
  497. */
  498. public function actionImportWithdrawsPaidFalse() {
  499. if (\Yii::$app->request->isPost) {
  500. $excelImportId = Yii::$app->request->post('excelImportId');
  501. $offset = Yii::$app->request->post('offset');
  502. $limit = Yii::$app->request->post('limit', 1000);
  503. $errorMsg = '';
  504. try {
  505. $excel = new Excel();
  506. $result = $excel->pageImportDataFromExcelTable('withdrawPaidFalse', $excelImportId, $offset, $limit);
  507. } catch (\Exception $e) {
  508. $result = false;
  509. $errorMsg = $e->getMessage();
  510. }
  511. // 还有数据
  512. if ($result === 1) {
  513. return static::notice(['finish' => false]);
  514. } elseif ($result === 0) {
  515. return static::notice(['finish' => true]);
  516. } else {
  517. return static::notice('error:' . $errorMsg, 400);
  518. }
  519. }
  520. }
  521. /**
  522. * 发票管理
  523. * @return mixed
  524. * @throws \yii\base\Exception
  525. * @throws \yii\web\HttpException
  526. */
  527. public function actionInvoiceAudit() {
  528. $filter = $this->filterCondition([
  529. 'userIds' => 'UI.USER_ID',
  530. 'createdAt' => 'IA.CREATED_AT',
  531. 'regType' => 'IA.REG_TYPE',
  532. 'filterStatus' => 'IA.AUDIT_STATUS',
  533. 'INVOICE_CODE' => 'IA.INVOICE_CODE',
  534. 'INVOICE_NUM' => 'IA.INVOICE_NUM',
  535. 'INVOICE_DATE' => 'IA.INVOICE_DATE',
  536. 'AMOUNT' => 'IA.AMOUNT',
  537. 'SN' => 'W.SN',
  538. ]);
  539. $condition = $filter['condition'];
  540. $params = $filter['params'];
  541. $data = InvoiceAudit::lists($condition, $params, [
  542. 'select' => 'IA.*,W.SN WITHDRAW_SN,U.URL INVOICE_URL',
  543. 'orderBy' => 'IA.CREATED_AT DESC',
  544. 'from' => InvoiceAudit::tableName() . ' AS IA',
  545. 'join' => [
  546. ['LEFT JOIN', UserInfo::tableName() . ' AS UI', 'IA.USER_ID=UI.USER_ID'],
  547. ['LEFT JOIN', Uploads::tableName() . ' AS U', 'IA.UPLOAD_ID=U.ID'],
  548. ['LEFT JOIN', Withdraw::tableName() . ' AS W', 'IA.WITHDRAW_ID=W.ID'],
  549. ],
  550. ]);
  551. $auditStatus = array_column(\Yii::$app->params['auditStatus'], null, 'value');
  552. foreach ($data['list'] as $key => $value) {
  553. $data['list'][$key]['BASE_INFO'] = Info::baseInfoZh($value['USER_ID']);
  554. $data['list'][$key]['CREATE_ADMIN_NAME'] = Admin::getAdminNameById($value['CREATE_ADMIN']);
  555. $data['list'][$key]['AUDIT_ADMIN_NAME'] = Admin::getAdminNameById($value['AUDIT_ADMIN']);
  556. $data['list'][$key]['STATUS_NAME'] = $auditStatus[$value['AUDIT_STATUS']]['label'];
  557. }
  558. return static::notice($data);
  559. }
  560. /**
  561. * 发票录入
  562. * @return mixed
  563. * @throws \yii\web\HttpException
  564. */
  565. public function actionInvoiceAuditAdd() {
  566. if (Yii::$app->request->isPost) {
  567. return parent::edit(InvoiceAuditForm::class, '发票录入成功', 'addByAdmin', ['addByAdmin'], null, function ($form, $result) {
  568. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  569. // Log::adminHandle('申请为' . $user['USER_NAME'] . '发票录入', 1, $result['USER_ID'], $user['USER_NAME']);
  570. });
  571. }
  572. // 获取全部注册类型
  573. $regTypes = RegType::getTypes();
  574. return static::notice(['regTypes' => $regTypes]);
  575. }
  576. /**
  577. * 发票信息获取
  578. * @return mixed
  579. * @throws \yii\base\Exception
  580. * @throws \yii\web\HttpException
  581. */
  582. public function actionInvoiceAuditGet() {
  583. $id = Yii::$app->request->get('id');
  584. $invoiceAudit = InvoiceAudit::findOneAsArray('ID=:ID AND AUDIT_STATUS=:AUDIT_STATUS', [':ID' => $id, ':AUDIT_STATUS' => \Yii::$app->params['auditStatus']['un']['value']]);
  585. if (!$invoiceAudit) {
  586. 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]);
  587. }
  588. $invoiceAudit['BASE_INFO'] = Info::baseInfoZh($invoiceAudit['USER_ID']);
  589. $invoiceAudit['INVOICE_DATE'] = $invoiceAudit['INVOICE_DATE'] ? (Date::validator(str_replace(['年', '月', '日'], ['-', '-', ''], $invoiceAudit['INVOICE_DATE']))?Date::convert(str_replace(['年', '月', '日'], ['-', '-', ''], $invoiceAudit['INVOICE_DATE'])):null) : null;
  590. $withdraw = Withdraw::findOneAsArray('ID=:ID', [':ID' => $invoiceAudit['WITHDRAW_ID']], 'ID,SN');
  591. 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']]);
  592. }
  593. /**
  594. * 发票信息修改
  595. * @return mixed
  596. * @throws \yii\db\Exception
  597. * @throws \yii\web\HttpException
  598. */
  599. public function actionInvoiceAuditEdit() {
  600. $formModel = new InvoiceAuditForm();
  601. $formModel->scenario = 'editByAdmin';
  602. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->editByAdmin()) {
  603. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  604. // Log::adminHandle('修改' . $user['USER_NAME'] . '发票录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  605. return static::notice('修改发票录入数据完成');
  606. }
  607. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  608. }
  609. /**
  610. * 发票信息审核
  611. * @return mixed
  612. * @throws \yii\db\Exception
  613. * @throws \yii\web\HttpException
  614. */
  615. public function actionInvoiceAuditAudit() {
  616. $formModel = new InvoiceAuditForm();
  617. $formModel->scenario = 'audit';
  618. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->audit()) {
  619. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  620. // Log::adminHandle('审核' . $user['USER_NAME'] . '发票录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  621. return static::notice('审核发票数据完成');
  622. }
  623. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  624. }
  625. /**
  626. * 发票信息删除
  627. * @return mixed
  628. * @throws \yii\db\Exception
  629. * @throws \yii\web\HttpException
  630. */
  631. public function actionInvoiceAuditDelete() {
  632. $result = static::delete(InvoiceAudit::class, null, function ($selected) {
  633. InvoiceAuditForm::delete($selected);
  634. // Log::adminHandle('删除发票信息');
  635. }, true);
  636. return $result;
  637. }
  638. /**
  639. * 调整会员业绩审核列表
  640. * @return mixed
  641. * @throws \yii\base\Exception
  642. * @throws \yii\web\HttpException
  643. */
  644. public function actionPerfAuditList() {
  645. $filter = $this->filterCondition([
  646. 'userIds' => 'UI.USER_ID',
  647. 'filterStatus' => 'PA.AUDIT_STATUS',
  648. 'SYSTEM_NAME' => 'UI.SYSTEM_ID',
  649. 'PV_1L' => 'PA.PV_1L',
  650. 'SURPLUS_1L' => 'PA.SURPLUS_1L',
  651. 'PV_2L' => 'PA.PV_2L',
  652. 'SURPLUS_2L' => 'PA.SURPLUS_2L',
  653. 'PV_3L' => 'PA.PV_3L',
  654. 'SURPLUS_3L' => 'PA.SURPLUS_3L',
  655. 'PV_4L' => 'PA.PV_4L',
  656. 'SURPLUS_4L' => 'PA.SURPLUS_4L',
  657. 'PV_5L' => 'PA.PV_5L',
  658. 'SURPLUS_5L' => 'PA.SURPLUS_5L',
  659. 'SURPLUS_LS' => 'PA.SURPLUS_LS',
  660. 'PERF_TYPE_NAME' => 'PA.PERF_TYPE',
  661. 'PERF_LOCATION_NAME' => 'PA.PERF_LOCATION',
  662. 'PERF_BEFORE' => 'PA.PERF_BEFORE',
  663. 'AMOUNT' => 'PA.AMOUNT',
  664. 'PERF_AFTER' => 'PA.PERF_AFTER',
  665. 'CREATED_AT' => 'PA.CREATED_AT',
  666. 'AUDITED_AT' => 'PA.AUDITED_AT',
  667. 'REMARK' => 'PA.REMARK',
  668. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  669. 'AUDIT_ADMIN_NAME' => 'ADMU.ADMIN_NAME',
  670. ]);
  671. $condition = $filter['condition'];
  672. $params = $filter['params'];
  673. $listObj = new PerfAuditList();
  674. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  675. return static::notice($data);
  676. }
  677. /**
  678. * 会员业绩调整列表导出
  679. * @return mixed
  680. * @throws \yii\db\Exception
  681. * @throws \yii\web\HttpException
  682. */
  683. public function actionPerfAuditListExport() {
  684. $filter = $this->filterCondition([
  685. 'userIds' => 'UI.USER_ID',
  686. 'filterStatus' => 'PA.AUDIT_STATUS',
  687. 'SYSTEM_NAME' => 'UI.SYSTEM_ID',
  688. 'PV_1L' => 'PA.PV_1L',
  689. 'SURPLUS_1L' => 'PA.SURPLUS_1L',
  690. 'PV_2L' => 'PA.PV_2L',
  691. 'SURPLUS_2L' => 'PA.SURPLUS_2L',
  692. 'PV_3L' => 'PA.PV_3L',
  693. 'SURPLUS_3L' => 'PA.SURPLUS_3L',
  694. 'PV_4L' => 'PA.PV_4L',
  695. 'SURPLUS_4L' => 'PA.SURPLUS_4L',
  696. 'PV_5L' => 'PA.PV_5L',
  697. 'SURPLUS_5L' => 'PA.SURPLUS_5L',
  698. 'SURPLUS_LS' => 'PA.SURPLUS_LS',
  699. 'PERF_TYPE_NAME' => 'PA.PERF_TYPE',
  700. 'PERF_LOCATION_NAME' => 'PA.PERF_LOCATION',
  701. 'PERF_BEFORE' => 'PA.PERF_BEFORE',
  702. 'AMOUNT' => 'PA.AMOUNT',
  703. 'PERF_AFTER' => 'PA.PERF_AFTER',
  704. 'CREATED_AT' => 'PA.CREATED_AT',
  705. 'AUDITED_AT' => 'PA.AUDITED_AT',
  706. 'REMARK' => 'PA.REMARK',
  707. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  708. 'AUDIT_ADMIN_NAME' => 'ADMU.ADMIN_NAME',
  709. ]);
  710. $form = new FinanceExportForm();
  711. $result = $form->run($filter, '会员业绩调整列表');
  712. if (!$result) {
  713. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  714. }
  715. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  716. }
  717. /**
  718. * 申请调整会员业绩
  719. * @return mixed
  720. * @throws \yii\web\HttpException
  721. */
  722. public function actionPerfApply() {
  723. if (\Yii::$app->request->isPost) { // 申请调整会员业绩成功
  724. return static::edit(ChangePerfForm::class, 'The application to adjust the member performance was successful', 'add', ['add'], null, function ($formModel, $result) {
  725. // 添加操作日志
  726. // Log::adminHandle('申请调整会员' . $formModel->userName . '的' . $formModel->location . '区业绩,调整额度为:' . $formModel->amount);
  727. });
  728. }
  729. $periodNum = Period::sentMaxPeriodNum();
  730. return static::notice(['periodNum' => $periodNum]);
  731. }
  732. /**
  733. * 获取调整会员的业绩
  734. * @return mixed
  735. * @throws \yii\web\HttpException
  736. */
  737. public function actionPerfApplyGet() {
  738. $periodNum = Period::sentMaxPeriodNum();
  739. 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) {
  740. // return static::notice('下一期【' . ($periodNum + 1) . '】已挂网,该期无法调整', 400);
  741. return static::notice('The next period [' . ($periodNum + 1) . '] has been connected to the net, and this period cannot be adjusted', 400);
  742. }
  743. $userName = \Yii::$app->request->get('userName');
  744. if (!$userId = Info::getUserIdByUserName($userName)) {
  745. return static::notice('Member does not exist', 400); // 会员不存在
  746. }
  747. $perf = PerfAudit::getUserPerfAndPerfPeriod($userId, $periodNum);
  748. return static::notice(array_merge(['REAL_NAME' => Info::getUserRealNameByUserId($userId)], $perf));
  749. }
  750. /**
  751. * 获取会员业绩审核信息
  752. * @return mixed
  753. * @throws \yii\web\HttpException
  754. */
  755. public function actionPerfAuditGet() {
  756. $id = Yii::$app->request->get('id');
  757. $perfAudit = PerfAudit::findOneAsArray('ID=:ID', [':ID' => $id]);
  758. if (!$perfAudit) {
  759. return static::notice('The data does not exist', 400); // 数据不存在
  760. }
  761. $perf = PerfAudit::getUserPerfAndPerfPeriod($perfAudit['USER_ID'], $perfAudit['PERIOD_NUM']);
  762. 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']]]);
  763. }
  764. /**
  765. * 审核通过会员业绩录入数据
  766. * @return mixed
  767. * @throws \yii\db\Exception
  768. * @throws \yii\web\HttpException
  769. */
  770. public function actionPerfAuditPass() {
  771. $formModel = new ChangePerfForm();
  772. $formModel->scenario = 'pass';
  773. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->pass()) {
  774. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  775. // Log::adminHandle('审核通过' . $user['USER_NAME'] . '调整会员业绩录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  776. return static::notice('审核通过调整会员业绩成功');
  777. }
  778. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  779. }
  780. /**
  781. * 审核会员业绩
  782. * @return mixed
  783. * @throws \yii\db\Exception
  784. * @throws \yii\web\HttpException
  785. */
  786. public function actionPerfAudit() {
  787. $formModel = new ChangePerfForm();
  788. $formModel->scenario = 'changeAudit';
  789. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeAudit()) {
  790. foreach ($result as $value) {
  791. $userName = Info::getUserNameByUserId($value['userId']);
  792. // Log::adminHandle('审核调整会员业绩录入数据' . $userName, 1, $value['userId'], $userName);
  793. }
  794. return static::notice('批量审核/审核拒绝会员业绩完成');
  795. }
  796. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  797. }
  798. /**
  799. * 删除审核会员业绩信息
  800. * @return mixed
  801. * @throws \yii\db\Exception
  802. * @throws \yii\web\HttpException
  803. */
  804. public function actionPerfAuditDelete() {
  805. $changePerfForm = new ChangePerfForm();
  806. $result = static::delete(PerfAudit::class, function ($selected) use ($changePerfForm) {
  807. $changePerfForm->beforeDelete($selected);
  808. // Log::adminHandle('删除审核会员余额信息');
  809. }, function ($selected) use ($changePerfForm) {
  810. $changePerfForm->delete($selected);
  811. // Log::adminHandle('删除审核会员余额信息');
  812. }, true);
  813. return $result;
  814. }
  815. /**
  816. * 交易类型管理
  817. * @return mixed
  818. * @throws \yii\web\HttpException
  819. */
  820. public function actionDealType() {
  821. $condition = '';
  822. $params = [];
  823. $data = DealType::lists($condition, $params, [
  824. 'orderBy' => 'DT.IS_PRESET ASC,DT.SORT_ORDER DESC',
  825. 'from' => DealType::tableName() . ' AS DT',
  826. ]);
  827. foreach ($data['list'] as $key => $value) {
  828. $data['list'][$key]['CREATE_ADMIN_NAME'] = Admin::getAdminNameById($value['CREATE_ADMIN']);
  829. $data['list'][$key]['UPDATE_ADMIN_NAME'] = Admin::getAdminNameById($value['UPDATE_ADMIN']);
  830. }
  831. return static::notice($data);
  832. }
  833. /**
  834. * 交易类型录入
  835. * @return mixed
  836. * @throws \yii\web\HttpException
  837. */
  838. public function actionDealTypeAdd() {
  839. if (Yii::$app->request->isPost) {
  840. return parent::edit(DealTypeForm::class, '交易类型添加成功', 'add', ['add'], null, function ($form, $result) {
  841. // Log::adminHandle('交易类型录入');
  842. });
  843. }
  844. }
  845. /**
  846. * 交易类型获取
  847. * @return mixed
  848. * @throws \yii\web\HttpException
  849. */
  850. public function actionDealTypeGet() {
  851. $id = Yii::$app->request->get('id');
  852. $dealType = DealType::findOneAsArray('ID=:ID', [':ID' => $id]);
  853. if (!$dealType) {
  854. return static::notice('The data does not exist', 400); // 数据不存在
  855. }
  856. 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']]);
  857. }
  858. /**
  859. * 交易类型修改
  860. * @return mixed
  861. * @throws \yii\db\Exception
  862. * @throws \yii\web\HttpException
  863. */
  864. public function actionDealTypeEdit() {
  865. $formModel = new DealTypeForm();
  866. $formModel->scenario = 'edit';
  867. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  868. // Log::adminHandle('修改交易类型');
  869. return static::notice('修改交易类型完成');
  870. }
  871. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  872. }
  873. /**
  874. * 交易类型删除
  875. * @return mixed
  876. * @throws \yii\db\Exception
  877. * @throws \yii\web\HttpException
  878. */
  879. public function actionDealTypeDelete() {
  880. return static::notice('无法删除', 400);
  881. $result = static::delete(DealType::class, null, function ($selected) {
  882. DealTypeForm::delete($selected);
  883. // Log::adminHandle('删除交易类型');
  884. }, true);
  885. return $result;
  886. }
  887. /**
  888. * 分页导入excel文件到待导入数据的表中
  889. * @return mixed
  890. * @throws \yii\base\Exception
  891. * @throws \yii\web\HttpException
  892. */
  893. public function actionImportChangeBalanceToExcelTable() {
  894. // 先上传到服务器文件
  895. if (\Yii::$app->request->isPost) {
  896. $excelImportId = Yii::$app->request->post('excelImportId');
  897. $rowCount = Yii::$app->request->post('rowCount');
  898. $startRow = Yii::$app->request->post('startRow');
  899. $limit = Yii::$app->request->post('limit', 1000);
  900. $errorMsg = '';
  901. try {
  902. $excel = new Excel();
  903. $result = $excel->pageImportDataFromExcel('changeBalance', $excelImportId, $rowCount, $startRow, $limit);
  904. } catch (\Exception $e) {
  905. $result = false;
  906. $errorMsg = $e->getMessage();
  907. }
  908. // 还有数据
  909. if ($result === 1) {
  910. return static::notice(['finish' => false]);
  911. } elseif ($result === 0) {
  912. return static::notice(['finish' => true]);
  913. } else {
  914. return static::notice('发生错误:' . $errorMsg, 400);
  915. }
  916. }
  917. }
  918. /**
  919. * 分页把待导入表中的数据导入到真正的数据中
  920. * @return mixed
  921. * @throws \yii\base\Exception
  922. * @throws \yii\web\HttpException
  923. */
  924. public function actionImportChangeBalance() {
  925. if (\Yii::$app->request->isPost) {
  926. $excelImportId = Yii::$app->request->post('excelImportId');
  927. $offset = Yii::$app->request->post('offset');
  928. $limit = Yii::$app->request->post('limit', 1000);
  929. $errorMsg = '';
  930. try {
  931. $excel = new Excel();
  932. $result = $excel->pageImportDataFromExcelTable('changeBalance', $excelImportId, $offset, $limit);
  933. } catch (\Exception $e) {
  934. $result = false;
  935. $errorMsg = $e->getMessage();
  936. }
  937. // 还有数据
  938. if ($result === 1) {
  939. return static::notice(['finish' => false]);
  940. } elseif ($result === 0) {
  941. return static::notice(['finish' => true]);
  942. } else {
  943. return static::notice('发生错误:' . $errorMsg, 400);
  944. }
  945. }
  946. }
  947. /**
  948. * 历史奖金余额
  949. * @return mixed
  950. * @throws \yii\base\Exception
  951. * @throws \yii\web\HttpException
  952. */
  953. public function actionHistoryBonus() {
  954. $filter = $this->filterCondition([
  955. 'USER_NAME' => 'USER_NAME',
  956. 'REAL_NAME' => 'REAL_NAME',
  957. 'DEC_LV_NAME' => 'DEC_LV',
  958. 'EMP_LV_NAME' => 'EMP_LV',
  959. 'IS_DEC' => 'IS_DEC',
  960. // 'DEC_ROLE_NAME' => 'DEC_ROLE_ID',
  961. 'SYSTEM_NAME' => 'SYSTEM_NAME',
  962. 'BONUS' => 'BONUS',
  963. // 'CF' => 'CF',
  964. // 'LX' => 'LX',
  965. 'WITHDRAW' => 'WITHDRAW',
  966. // 'WITHDRAW_TAX' => 'WITHDRAW_TAX',
  967. // 'WITHDRAW_DEDUCT' => 'WITHDRAW_DEDUCT',
  968. 'WITHDRAW_REAL' => 'WITHDRAW_REAL',
  969. 'WITHDRAW_FAIL' => 'WITHDRAW_FAIL',
  970. 'USER_STATUS_NAME' => 'USER_STATUS',
  971. 'USER_STATUS_AT' => 'USER_STATUS_AT',
  972. // 'HIGHEST_EMP_LV_NAME' => 'HIGHEST_EMP_LV',
  973. 'PERIOD_AT' => 'PERIOD_AT',
  974. // 'DEC_DEC_ROLE_NAME' => 'DEC_DEC_ROLE_ID',
  975. 'DEC_USER_NAME' => 'DEC_USER_NAME',
  976. 'DEC_REAL_NAME' => 'DEC_REAL_NAME',
  977. 'MOBILE' => 'MOBILE',
  978. 'TEL' => 'TEL',
  979. 'AREA' => [
  980. 'FIELD' => ['PROVINCE', 'CITY', 'COUNTY'],
  981. 'BIND' => ['PROVINCE', 'CITY', 'COUNTY'],
  982. ],
  983. // 'SUB_COM_NAME' => 'SUB_COM_ID',
  984. // 'IS_DIRECT_SELLER' => 'IS_DIRECT_SELLER',
  985. 'BACKUP_AT' => 'BACKUP_AT',
  986. ]);
  987. $condition = $filter['condition'];
  988. $params = $filter['params'];
  989. $listObj = new HistoryBonusList();
  990. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  991. return static::notice($data);
  992. }
  993. /**
  994. * 历史奖金余额导出
  995. * @return mixed
  996. * @throws \yii\db\Exception
  997. * @throws \yii\web\HttpException
  998. */
  999. public function actionHistoryBonusExport() {
  1000. $filter = $this->filterCondition([
  1001. 'USER_NAME' => 'USER_NAME',
  1002. 'REAL_NAME' => 'REAL_NAME',
  1003. 'DEC_LV_NAME' => 'DEC_LV',
  1004. 'EMP_LV_NAME' => 'EMP_LV',
  1005. 'IS_DEC' => 'IS_DEC',
  1006. 'DEC_ROLE_NAME' => 'DEC_ROLE_ID',
  1007. 'SYSTEM_NAME' => 'SYSTEM_NAME',
  1008. 'BONUS' => 'BONUS',
  1009. 'CF' => 'CF',
  1010. 'LX' => 'LX',
  1011. 'WITHDRAW' => 'WITHDRAW',
  1012. 'WITHDRAW_TAX' => 'WITHDRAW_TAX',
  1013. 'WITHDRAW_DEDUCT' => 'WITHDRAW_DEDUCT',
  1014. 'WITHDRAW_REAL' => 'WITHDRAW_REAL',
  1015. 'WITHDRAW_FAIL' => 'WITHDRAW_FAIL',
  1016. 'USER_STATUS_NAME' => 'USER_STATUS',
  1017. 'USER_STATUS_AT' => 'USER_STATUS_AT',
  1018. 'HIGHEST_EMP_LV_NAME' => 'HIGHEST_EMP_LV',
  1019. 'PERIOD_AT' => 'PERIOD_AT',
  1020. 'DEC_DEC_ROLE_NAME' => 'DEC_DEC_ROLE_ID',
  1021. 'DEC_USER_NAME' => 'DEC_USER_NAME',
  1022. 'DEC_REAL_NAME' => 'DEC_REAL_NAME',
  1023. 'MOBILE' => 'MOBILE',
  1024. 'TEL' => 'TEL',
  1025. 'AREA' => [
  1026. 'FIELD' => ['PROVINCE', 'CITY', 'COUNTY'],
  1027. 'BIND' => ['PROVINCE', 'CITY', 'COUNTY'],
  1028. ],
  1029. 'SUB_COM_NAME' => 'SUB_COM_ID',
  1030. 'IS_DIRECT_SELLER' => 'IS_DIRECT_SELLER',
  1031. 'BACKUP_AT' => 'BACKUP_AT',
  1032. ]);
  1033. $form = new FinanceExportForm();
  1034. $result = $form->run($filter, '历史奖金余额');
  1035. if (!$result) {
  1036. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1037. }
  1038. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  1039. }
  1040. /**
  1041. * 充值列表
  1042. * @return mixed
  1043. * @throws \yii\base\Exception
  1044. * @throws \yii\web\HttpException
  1045. */
  1046. public function actionRecharge()
  1047. {
  1048. $filter = $this->filterCondition([
  1049. 'SN' => 'R.SN',
  1050. 'USER_NAME' => 'UI.USER_NAME',
  1051. 'AMOUNT' => 'R.AMOUNT',
  1052. 'AUDIT_STATUS' => 'R.AUDIT_STATUS',
  1053. 'BANK_NO' => 'R.BANK_NO',
  1054. 'CREATED_AT' => 'R.CREATED_AT',
  1055. ]);
  1056. $condition = $filter['condition'];
  1057. $params = $filter['params'];
  1058. $listObj = new RechargeList();
  1059. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  1060. return static::notice($data);
  1061. }
  1062. /**
  1063. * 充值导出
  1064. * @return mixed
  1065. * @throws \yii\db\Exception
  1066. * @throws \yii\web\HttpException
  1067. */
  1068. public function actionRechargeExport() {
  1069. $filter = $this->filterCondition([
  1070. 'SN' => 'R.SN',
  1071. 'USER_NAME' => 'UI.USER_NAME',
  1072. 'AMOUNT' => 'R.AMOUNT',
  1073. 'AUDIT_STATUS' => 'R.AUDIT_STATUS',
  1074. 'BANK_NO' => 'R.BANK_NO',
  1075. 'CREATED_AT' => 'R.CREATED_AT',
  1076. ]);
  1077. $form = new FinanceExportForm();
  1078. $result = $form->run($filter, 'Recharge'); // 充值申请
  1079. if (!$result) {
  1080. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1081. }
  1082. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  1083. }
  1084. /**
  1085. * 改变充值状态
  1086. * @return mixed
  1087. * @throws \yii\base\Exception
  1088. * @throws \yii\db\Exception
  1089. * @throws \yii\web\HttpException
  1090. */
  1091. public function actionRechargeStatus() {
  1092. $id = Yii::$app->request->get('id');
  1093. if (Yii::$app->request->isPost) {
  1094. $formModel = new RechargeForm();
  1095. $formModel->scenario = 'statusByAdmin';
  1096. //$formModel->id = $id;
  1097. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  1098. foreach ($result['logs'] as $k => $value) {
  1099. $userName = Info::getUserNameByUserId($k);
  1100. // Log::adminHandle('为会员' . $userName . '的充值流水号为' . $value . '改变充值状态至' . Recharge::STATUS_NAME[$result['status']], 1, $k, $userName);
  1101. }
  1102. return static::notice('Status setting succeeded'); // 状态设置成功
  1103. } else {
  1104. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  1105. }
  1106. }
  1107. // 所有开户行
  1108. $statusArray = [2=>'Approve',3=>'Reject']; // 2=>'审核通过',3=>'审核拒绝'
  1109. return static::notice(['statusArray' => $statusArray]);
  1110. }
  1111. /**
  1112. * 连点操作校验码获取
  1113. * @return mixed
  1114. * @throws \yii\web\HttpException
  1115. */
  1116. public function actionMultPoint() {
  1117. $verifyCode = $this->_random(8,1);
  1118. $adminId = \Yii::$app->user->id;
  1119. if (\Yii::$app->request->isPost) {
  1120. $opType = Yii::$app->request->post('opType');
  1121. if($opType==1){
  1122. $redisName = 'balanceCode';
  1123. }elseif ($opType==2){
  1124. $redisName = 'withdrawAudit';
  1125. }
  1126. }
  1127. \Yii::$app->redis->set($redisName.'_'.$adminId,$verifyCode);
  1128. return static::notice([$redisName => $verifyCode]);
  1129. }
  1130. /**
  1131. * 生成随机数
  1132. * @param $length
  1133. * @param int $numeric
  1134. * @return string
  1135. */
  1136. private function _random($length, $numeric = 0) {
  1137. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  1138. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  1139. $hash = '';
  1140. $max = strlen($seed) - 1;
  1141. for ($i = 0; $i < $length; $i++) {
  1142. $hash .= $seed[mt_rand(0, $max)];
  1143. }
  1144. return $hash;
  1145. }
  1146. }