FinanceController.php 54 KB

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