FinanceController.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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. //4047 国家筛选
  282. 'COUNTRY_ID' => 'U.COUNTRY_ID',
  283. 'COUNTRY_NAME' => 'CN.NAME',
  284. ]);
  285. $condition = $filter['condition'];
  286. $params = $filter['params'];
  287. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  288. if (!$isSuper) {
  289. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  290. $adminCountry = AdminCountry::getCountry($adminId);
  291. $quotedAdminCountry = array_map(function($item) {
  292. return "'" . addslashes($item) . "'";
  293. }, $adminCountry);
  294. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  295. }
  296. $listObj = new TransferList();
  297. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  298. return static::notice($data);
  299. }
  300. /**
  301. * 转账列表导出
  302. * @return mixed
  303. * @throws \yii\db\Exception
  304. * @throws \yii\web\HttpException
  305. */
  306. public function actionTransferListExport() {
  307. $filter = $this->filterCondition([
  308. 'TRANSFER_SN' => 'TRANSFER_SN',
  309. 'LAST_OUT_USER_NAME' => 'LAST_OUT_USER_NAME',
  310. 'LAST_OUT_REAL_NAME' => 'LAST_OUT_REAL_NAME',
  311. 'LAST_OUT_DEC_LV_NAME' => 'LAST_OUT_DEC_LV',
  312. 'LAST_OUT_DEC_ROLE_NAME' => 'LAST_OUT_DEC_ROLE_ID',
  313. 'OUT_WALLET' => 'OUT_WALLET',
  314. 'LAST_OUT_SYSTEM_NAME' => 'LAST_OUT_SYSTEM_ID',
  315. 'LAST_IN_USER_NAME' => 'LAST_IN_USER_NAME',
  316. 'LAST_IN_REAL_NAME' => 'LAST_IN_REAL_NAME',
  317. 'LAST_IN_DEC_LV_NAME' => 'LAST_IN_DEC_LV',
  318. 'IN_WALLET' => 'IN_WALLET',
  319. 'LAST_IN_SYSTEM_NAME' => 'LAST_IN_SYSTEM_ID',
  320. 'ORI_AMOUNT' => 'ORI_AMOUNT',
  321. 'FEE' => 'FEE',
  322. 'AMOUNT' => 'AMOUNT',
  323. 'CREATED_AT' => 'CREATED_AT',
  324. 'PERIOD_NUM' => 'PERIOD_NUM',
  325. 'REMARK' => 'REMARK',
  326. ]);
  327. $condition = $filter['condition'];
  328. $params = $filter['params'];
  329. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  330. if (!$isSuper) {
  331. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  332. $adminCountry = AdminCountry::getCountry($adminId);
  333. $quotedAdminCountry = array_map(function($item) {
  334. return "'" . addslashes($item) . "'";
  335. }, $adminCountry);
  336. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  337. }
  338. $form = new FinanceExportForm();
  339. $result = $form->run(['condition' => $condition, 'params' => $params], Yii::t('ctx', 'financeControllerTransferListExport')); // 转账列表
  340. if (!$result) {
  341. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  342. }
  343. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  344. }
  345. /**
  346. * 提现列表
  347. * @return mixed
  348. * @throws \yii\base\Exception
  349. * @throws \yii\web\HttpException
  350. */
  351. public function actionWithdraw() {
  352. $filter = $this->filterCondition([
  353. 'SN' => 'W.SN',
  354. 'WITHDRAW_PERIOD_NUM' => 'W.WITHDRAW_PERIOD_NUM',
  355. 'filterStatus' => 'W.AUDIT_STATUS',
  356. 'CREATED_AT' => 'W.CREATED_AT',
  357. 'USER_NAME' => 'U.USER_NAME',
  358. 'REAL_AMOUNT' => 'W.REAL_AMOUNT',
  359. //4047新增 “会员姓名”、“国家”、“提现银行”、“手机号"
  360. 'REAL_NAME' => 'U.REAL_NAME',
  361. 'COUNTRY_ID' => 'U.COUNTRY_ID',
  362. 'COUNTRY_NAME' => 'CN.NAME',
  363. 'OPEN_BANK' => 'U.OPEN_BANK',
  364. 'MOBILE' => 'U.MOBILE',
  365. ]);
  366. $condition = $filter['condition'];
  367. $params = $filter['params'];
  368. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  369. if (!$isSuper) {
  370. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  371. $adminCountry = AdminCountry::getCountry($adminId);
  372. $quotedAdminCountry = array_map(function($item) {
  373. return "'" . addslashes($item) . "'";
  374. }, $adminCountry);
  375. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  376. }
  377. $listObj = new WithdrawList();
  378. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  379. return static::notice($data);
  380. }
  381. /**
  382. * 后台新增提现
  383. * @return mixed
  384. * @throws \yii\web\HttpException
  385. */
  386. public function actionWithdrawAdd() {
  387. if (Yii::$app->request->isPost) {// 新增会员提现成功
  388. return parent::edit(WithdrawForm::class, Yii::t('ctx', 'addedMemberSuccessfullyWithdrewCash'), 'addByAdmin', ['add'], null, function ($form, $result) {
  389. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  390. // Log::adminHandle('申请为' . $user['USER_NAME'] . '提现' . $result['WITHDRAW_AMOUNT'], 1, $result['USER_ID'], $user['USER_NAME']);
  391. });
  392. }
  393. // 获取全部注册类型
  394. $regTypes = RegType::getTypes();
  395. return static::notice(['regTypes' => $regTypes]);
  396. }
  397. /**
  398. * 提现数据获取
  399. * @return mixed
  400. * @throws \yii\base\Exception
  401. * @throws \yii\web\HttpException
  402. */
  403. public function actionWithdrawGet() {
  404. $id = Yii::$app->request->get('id');
  405. $withdraw = Withdraw::findOneAsArray('ID=:ID', [':ID' => $id]);
  406. if (!$withdraw) {
  407. return static::notice(Yii::t('ctx', 'dataDoesNotExists'), 400); // 数据不存在
  408. }
  409. $withdraw['BASE_INFO'] = Info::baseInfoZh($withdraw['USER_ID']);
  410. $withdraw['PLAN_PAID_AT'] = $withdraw['PLAN_PAID_AT'] ? Date::convert($withdraw['PLAN_PAID_AT']) : null;
  411. return static::notice(['id' => $withdraw['ID'], 'baseInfo' => $withdraw['BASE_INFO'], 'amount' => Tool::formatPrice($withdraw['AMOUNT']), 'planPaidAt' => $withdraw['PLAN_PAID_AT'], 'remark' => $withdraw['REMARK']]);
  412. }
  413. /**
  414. * 修改提现
  415. * @return mixed
  416. * @throws \yii\db\Exception
  417. * @throws \yii\web\HttpException
  418. */
  419. public function actionWithdrawEdit() {
  420. $id = Yii::$app->request->get('id');
  421. if (Yii::$app->request->isPost) {
  422. $formModel = new WithdrawForm();
  423. $formModel->scenario = 'editByAdmin';
  424. $formModel->id = $id;
  425. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->editByAdmin()) {
  426. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  427. // Log::adminHandle('修改提现信息,ID为:' . $result['ID'], 1, $result['USER_ID'], $user['USER_NAME']);
  428. return static::notice(Yii::t('ctx', 'withdrawalInformationModifiedSuccessfully')); // 修改提现信息成功
  429. } else {
  430. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  431. }
  432. }
  433. return static::notice('Illegal request', 400); // 非法请求
  434. }
  435. /**
  436. * 改变状态
  437. * @return mixed
  438. * @throws \yii\base\Exception
  439. * @throws \yii\db\Exception
  440. * @throws \yii\web\HttpException
  441. */
  442. public function actionWithdrawStatus() {
  443. $id = Yii::$app->request->get('id');
  444. if (Yii::$app->request->isPost) {
  445. $formModel = new WithdrawForm();
  446. $formModel->scenario = 'statusByAdmin';
  447. $formModel->id = $id;
  448. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  449. foreach ($result['logs'] as $k => $value) {
  450. $userName = Info::getUserNameByUserId($k);
  451. // Log::adminHandle('为会员' . $userName . '的提现流水号为' . $value . '改变提现状态至' . Withdraw::STATUS_NAME[$result['status']], 1, $k, $userName);
  452. }
  453. return static::notice(Yii::t('ctx', 'statusSettingSucceeded')); // 状态设置成功
  454. } else {
  455. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  456. }
  457. }
  458. return static::notice(Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
  459. }
  460. /**
  461. * 提现明细导出到excel
  462. * @return mixed
  463. * @throws \yii\db\Exception
  464. * @throws \yii\web\HttpException
  465. */
  466. public function actionWithdrawExport() {
  467. $filter = $this->filterCondition([
  468. 'SN' => 'W.SN',
  469. 'CREATED_AT' => 'W.CREATED_AT',
  470. 'AUDIT_STATUS_NAME' => 'W.AUDIT_STATUS',
  471. 'USER_NAME' => 'U.USER_NAME',
  472. 'WITHDRAW_PERIOD_NUM' => 'W.WITHDRAW_PERIOD_NUM',
  473. 'REAL_AMOUNT' => 'W.REAL_AMOUNT'
  474. ]);
  475. // $selectedIds = \Yii::$app->request->get('selectedIds', []);
  476. // if ($selectedIds) {
  477. // $filter['condition'] .= " AND W.ID IN (" . implode(',', $selectedIds) . ")";
  478. // }
  479. if (isset($filter['request']['filterStatus'])) {
  480. $status = explode(',',$filter['request']['filterStatus']);
  481. $status = end($status);
  482. if (is_numeric($status)) {
  483. $filter['condition'] .= " AND W.AUDIT_STATUS = $status";
  484. }
  485. }
  486. if (isset($filter['request']['WITHDRAW_PERIOD_NUM'])) {
  487. $period = explode(',',$filter['request']['WITHDRAW_PERIOD_NUM']);
  488. $periodNum = isset($period[1]) ? $period[1] : '';
  489. if (is_numeric($periodNum)) {
  490. $filter['condition'] .= " AND W.WITHDRAW_PERIOD_NUM = $periodNum";
  491. }
  492. }
  493. $condition = $filter['condition'];
  494. $params = $filter['params'];
  495. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  496. if (!$isSuper) {
  497. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  498. $adminCountry = AdminCountry::getCountry($adminId);
  499. $quotedAdminCountry = array_map(function($item) {
  500. return "'" . addslashes($item) . "'";
  501. }, $adminCountry);
  502. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  503. }
  504. $form = new FinanceExportForm();
  505. $result = $form->run(['condition' => $condition, 'params' => $params], Yii::t('ctx', 'exportWithdrawApplyExcelName')); // 提现申请
  506. if (!$result) {
  507. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  508. }
  509. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  510. }
  511. /**
  512. * 分页导入excel文件到待导入数据的表中
  513. * @return mixed
  514. * @throws \yii\base\Exception
  515. * @throws \yii\web\HttpException
  516. */
  517. public function actionImportWithdrawsToExcelTable() {
  518. // 先上传到服务器文件
  519. if (\Yii::$app->request->isPost) {
  520. $excelImportId = Yii::$app->request->post('excelImportId');
  521. $rowCount = Yii::$app->request->post('rowCount');
  522. $startRow = Yii::$app->request->post('startRow');
  523. $limit = Yii::$app->request->post('limit', 1000);
  524. $errorMsg = '';
  525. try {
  526. $excel = new Excel();
  527. $result = $excel->pageImportDataFromExcel('withdrawPaidFalse', $excelImportId, $rowCount, $startRow, $limit);
  528. } catch (\Exception $e) {
  529. $result = false;
  530. $errorMsg = $e->getMessage();
  531. }
  532. // 还有数据
  533. if ($result === 1) {
  534. return static::notice(['finish' => false]);
  535. } elseif ($result === 0) {
  536. return static::notice(['finish' => true]);
  537. } else {
  538. return static::notice('Error:' . $errorMsg, 400);
  539. }
  540. }
  541. }
  542. /**
  543. * 分页把待导入表中的数据导入到真正的数据中
  544. * @return mixed
  545. * @throws \yii\base\Exception
  546. * @throws \yii\web\HttpException
  547. */
  548. public function actionImportWithdrawsPaidFalse() {
  549. if (\Yii::$app->request->isPost) {
  550. $excelImportId = Yii::$app->request->post('excelImportId');
  551. $offset = Yii::$app->request->post('offset');
  552. $limit = Yii::$app->request->post('limit', 1000);
  553. $errorMsg = '';
  554. try {
  555. $excel = new Excel();
  556. $result = $excel->pageImportDataFromExcelTable('withdrawPaidFalse', $excelImportId, $offset, $limit);
  557. } catch (\Exception $e) {
  558. $result = false;
  559. $errorMsg = $e->getMessage();
  560. }
  561. // 还有数据
  562. if ($result === 1) {
  563. return static::notice(['finish' => false]);
  564. } elseif ($result === 0) {
  565. return static::notice(['finish' => true]);
  566. } else {
  567. return static::notice('error:' . $errorMsg, 400);
  568. }
  569. }
  570. }
  571. /**
  572. * 发票管理
  573. * @return mixed
  574. * @throws \yii\base\Exception
  575. * @throws \yii\web\HttpException
  576. */
  577. public function actionInvoiceAudit() {
  578. $filter = $this->filterCondition([
  579. 'userIds' => 'UI.USER_ID',
  580. 'createdAt' => 'IA.CREATED_AT',
  581. 'regType' => 'IA.REG_TYPE',
  582. 'filterStatus' => 'IA.AUDIT_STATUS',
  583. 'INVOICE_CODE' => 'IA.INVOICE_CODE',
  584. 'INVOICE_NUM' => 'IA.INVOICE_NUM',
  585. 'INVOICE_DATE' => 'IA.INVOICE_DATE',
  586. 'AMOUNT' => 'IA.AMOUNT',
  587. 'SN' => 'W.SN',
  588. ]);
  589. $condition = $filter['condition'];
  590. $params = $filter['params'];
  591. $data = InvoiceAudit::lists($condition, $params, [
  592. 'select' => 'IA.*,W.SN WITHDRAW_SN,U.URL INVOICE_URL',
  593. 'orderBy' => 'IA.CREATED_AT DESC',
  594. 'from' => InvoiceAudit::tableName() . ' AS IA',
  595. 'join' => [
  596. ['LEFT JOIN', UserInfo::tableName() . ' AS UI', 'IA.USER_ID=UI.USER_ID'],
  597. ['LEFT JOIN', Uploads::tableName() . ' AS U', 'IA.UPLOAD_ID=U.ID'],
  598. ['LEFT JOIN', Withdraw::tableName() . ' AS W', 'IA.WITHDRAW_ID=W.ID'],
  599. ],
  600. ]);
  601. $auditStatus = array_column(Tool::paramConvert(\Yii::$app->params['auditStatus']), null, 'value');
  602. foreach ($data['list'] as $key => $value) {
  603. $data['list'][$key]['BASE_INFO'] = Info::baseInfoZh($value['USER_ID']);
  604. $data['list'][$key]['CREATE_ADMIN_NAME'] = Admin::getAdminNameById($value['CREATE_ADMIN']);
  605. $data['list'][$key]['AUDIT_ADMIN_NAME'] = Admin::getAdminNameById($value['AUDIT_ADMIN']);
  606. $data['list'][$key]['STATUS_NAME'] = $auditStatus[$value['AUDIT_STATUS']]['label'];
  607. }
  608. return static::notice($data);
  609. }
  610. /**
  611. * 发票录入
  612. * @return mixed
  613. * @throws \yii\web\HttpException
  614. */
  615. public function actionInvoiceAuditAdd() {
  616. if (Yii::$app->request->isPost) {
  617. return parent::edit(InvoiceAuditForm::class, Yii::t('ctx', 'invoiceEnteredSuccessfully'), 'addByAdmin', ['addByAdmin'], null, function ($form, $result) {
  618. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  619. // Log::adminHandle('申请为' . $user['USER_NAME'] . '发票录入', 1, $result['USER_ID'], $user['USER_NAME']);
  620. });
  621. }
  622. // 获取全部注册类型
  623. $regTypes = RegType::getTypes();
  624. return static::notice(['regTypes' => $regTypes]);
  625. }
  626. /**
  627. * 发票信息获取
  628. * @return mixed
  629. * @throws \yii\base\Exception
  630. * @throws \yii\web\HttpException
  631. */
  632. public function actionInvoiceAuditGet() {
  633. $id = Yii::$app->request->get('id');
  634. $invoiceAudit = InvoiceAudit::findOneAsArray('ID=:ID AND AUDIT_STATUS=:AUDIT_STATUS', [':ID' => $id, ':AUDIT_STATUS' => \Yii::$app->params['auditStatus']['un']['value']]);
  635. if (!$invoiceAudit) {
  636. 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]);
  637. }
  638. $invoiceAudit['BASE_INFO'] = Info::baseInfoZh($invoiceAudit['USER_ID']);
  639. $invoiceAudit['INVOICE_DATE'] = $invoiceAudit['INVOICE_DATE'] ? (Date::validator(str_replace(['年', '月', '日'], ['-', '-', ''], $invoiceAudit['INVOICE_DATE']))?Date::convert(str_replace(['年', '月', '日'], ['-', '-', ''], $invoiceAudit['INVOICE_DATE'])):null) : null;
  640. $withdraw = Withdraw::findOneAsArray('ID=:ID', [':ID' => $invoiceAudit['WITHDRAW_ID']], 'ID,SN');
  641. 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']]);
  642. }
  643. /**
  644. * 发票信息修改
  645. * @return mixed
  646. * @throws \yii\db\Exception
  647. * @throws \yii\web\HttpException
  648. */
  649. public function actionInvoiceAuditEdit() {
  650. $formModel = new InvoiceAuditForm();
  651. $formModel->scenario = 'editByAdmin';
  652. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->editByAdmin()) {
  653. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  654. // Log::adminHandle('修改' . $user['USER_NAME'] . '发票录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  655. return static::notice(Yii::t('ctx', 'modifyInvoiceEntryCompleted'));
  656. }
  657. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  658. }
  659. /**
  660. * 发票信息审核
  661. * @return mixed
  662. * @throws \yii\db\Exception
  663. * @throws \yii\web\HttpException
  664. */
  665. public function actionInvoiceAuditAudit() {
  666. $formModel = new InvoiceAuditForm();
  667. $formModel->scenario = 'audit';
  668. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->audit()) {
  669. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  670. // Log::adminHandle('审核' . $user['USER_NAME'] . '发票录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  671. return static::notice(Yii::t('ctx', 'reviewInvoiceDataCompleted'));
  672. }
  673. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  674. }
  675. /**
  676. * 发票信息删除
  677. * @return mixed
  678. * @throws \yii\db\Exception
  679. * @throws \yii\web\HttpException
  680. */
  681. public function actionInvoiceAuditDelete() {
  682. $result = static::delete(InvoiceAudit::class, null, function ($selected) {
  683. InvoiceAuditForm::delete($selected);
  684. // Log::adminHandle('删除发票信息');
  685. }, true);
  686. return $result;
  687. }
  688. /**
  689. * 调整会员业绩审核列表
  690. * @return mixed
  691. * @throws \yii\base\Exception
  692. * @throws \yii\web\HttpException
  693. */
  694. public function actionPerfAuditList() {
  695. $filter = $this->filterCondition([
  696. 'userIds' => 'UI.USER_ID',
  697. 'filterStatus' => 'PA.AUDIT_STATUS',
  698. 'SYSTEM_NAME' => 'UI.SYSTEM_ID',
  699. 'PV_1L' => 'PA.PV_1L',
  700. 'SURPLUS_1L' => 'PA.SURPLUS_1L',
  701. 'PV_2L' => 'PA.PV_2L',
  702. 'SURPLUS_2L' => 'PA.SURPLUS_2L',
  703. 'PV_3L' => 'PA.PV_3L',
  704. 'SURPLUS_3L' => 'PA.SURPLUS_3L',
  705. 'PV_4L' => 'PA.PV_4L',
  706. 'SURPLUS_4L' => 'PA.SURPLUS_4L',
  707. 'PV_5L' => 'PA.PV_5L',
  708. 'SURPLUS_5L' => 'PA.SURPLUS_5L',
  709. 'SURPLUS_LS' => 'PA.SURPLUS_LS',
  710. 'PERF_TYPE_NAME' => 'PA.PERF_TYPE',
  711. 'PERF_LOCATION_NAME' => 'PA.PERF_LOCATION',
  712. 'PERF_BEFORE' => 'PA.PERF_BEFORE',
  713. 'AMOUNT' => 'PA.AMOUNT',
  714. 'PERF_AFTER' => 'PA.PERF_AFTER',
  715. 'CREATED_AT' => 'PA.CREATED_AT',
  716. 'AUDITED_AT' => 'PA.AUDITED_AT',
  717. 'REMARK' => 'PA.REMARK',
  718. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  719. 'AUDIT_ADMIN_NAME' => 'ADMU.ADMIN_NAME',
  720. ]);
  721. $condition = $filter['condition'];
  722. $params = $filter['params'];
  723. $listObj = new PerfAuditList();
  724. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  725. return static::notice($data);
  726. }
  727. /**
  728. * 会员业绩调整列表导出
  729. * @return mixed
  730. * @throws \yii\db\Exception
  731. * @throws \yii\web\HttpException
  732. */
  733. public function actionPerfAuditListExport() {
  734. $filter = $this->filterCondition([
  735. 'userIds' => 'UI.USER_ID',
  736. 'filterStatus' => 'PA.AUDIT_STATUS',
  737. 'SYSTEM_NAME' => 'UI.SYSTEM_ID',
  738. 'PV_1L' => 'PA.PV_1L',
  739. 'SURPLUS_1L' => 'PA.SURPLUS_1L',
  740. 'PV_2L' => 'PA.PV_2L',
  741. 'SURPLUS_2L' => 'PA.SURPLUS_2L',
  742. 'PV_3L' => 'PA.PV_3L',
  743. 'SURPLUS_3L' => 'PA.SURPLUS_3L',
  744. 'PV_4L' => 'PA.PV_4L',
  745. 'SURPLUS_4L' => 'PA.SURPLUS_4L',
  746. 'PV_5L' => 'PA.PV_5L',
  747. 'SURPLUS_5L' => 'PA.SURPLUS_5L',
  748. 'SURPLUS_LS' => 'PA.SURPLUS_LS',
  749. 'PERF_TYPE_NAME' => 'PA.PERF_TYPE',
  750. 'PERF_LOCATION_NAME' => 'PA.PERF_LOCATION',
  751. 'PERF_BEFORE' => 'PA.PERF_BEFORE',
  752. 'AMOUNT' => 'PA.AMOUNT',
  753. 'PERF_AFTER' => 'PA.PERF_AFTER',
  754. 'CREATED_AT' => 'PA.CREATED_AT',
  755. 'AUDITED_AT' => 'PA.AUDITED_AT',
  756. 'REMARK' => 'PA.REMARK',
  757. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  758. 'AUDIT_ADMIN_NAME' => 'ADMU.ADMIN_NAME',
  759. ]);
  760. $form = new FinanceExportForm();
  761. $result = $form->run($filter, Yii::t('ctx', 'memberPerformanceAdjustmentList'));
  762. if (!$result) {
  763. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  764. }
  765. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  766. }
  767. /**
  768. * 申请调整会员业绩
  769. * @return mixed
  770. * @throws \yii\web\HttpException
  771. */
  772. public function actionPerfApply() {
  773. if (\Yii::$app->request->isPost) { // 申请调整会员业绩成功
  774. return static::edit(ChangePerfForm::class, Yii::t('ctx', 'applicationAdjustMemberPerfSuccess'), 'add', ['add'], null, function ($formModel, $result) {
  775. // 添加操作日志
  776. // Log::adminHandle('申请调整会员' . $formModel->userName . '的' . $formModel->location . '区业绩,调整额度为:' . $formModel->amount);
  777. });
  778. }
  779. $periodNum = Period::sentMaxPeriodNum();
  780. return static::notice(['periodNum' => $periodNum]);
  781. }
  782. /**
  783. * 获取调整会员的业绩
  784. * @return mixed
  785. * @throws \yii\web\HttpException
  786. */
  787. public function actionPerfApplyGet() {
  788. $periodNum = Period::sentMaxPeriodNum();
  789. 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) {
  790. // return static::notice('下一期【' . ($periodNum + 1) . '】已挂网,该期无法调整', 400);
  791. return static::notice(Yii::t('ctx', 'nextPeriodConnectedNetCannotAdjusted',[
  792. 'periodNum' => $periodNum + 1
  793. ]), 400);
  794. }
  795. $userName = \Yii::$app->request->get('userName');
  796. if (!$userId = Info::getUserIdByUserName($userName)) {
  797. return static::notice(Yii::t('ctx', 'memberDoesNotExist'), 400); // 会员不存在
  798. }
  799. $perf = PerfAudit::getUserPerfAndPerfPeriod($userId, $periodNum);
  800. return static::notice(array_merge(['REAL_NAME' => Info::getUserRealNameByUserId($userId)], $perf));
  801. }
  802. /**
  803. * 获取会员业绩审核信息
  804. * @return mixed
  805. * @throws \yii\web\HttpException
  806. */
  807. public function actionPerfAuditGet() {
  808. $id = Yii::$app->request->get('id');
  809. $perfAudit = PerfAudit::findOneAsArray('ID=:ID', [':ID' => $id]);
  810. if (!$perfAudit) {
  811. return static::notice(Yii::t('ctx', 'dataDoesNotExists'), 400); // 数据不存在
  812. }
  813. $perf = PerfAudit::getUserPerfAndPerfPeriod($perfAudit['USER_ID'], $perfAudit['PERIOD_NUM']);
  814. 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']]]);
  815. }
  816. /**
  817. * 审核通过会员业绩录入数据
  818. * @return mixed
  819. * @throws \yii\db\Exception
  820. * @throws \yii\web\HttpException
  821. */
  822. public function actionPerfAuditPass() {
  823. $formModel = new ChangePerfForm();
  824. $formModel->scenario = 'pass';
  825. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->pass()) {
  826. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  827. // Log::adminHandle('审核通过' . $user['USER_NAME'] . '调整会员业绩录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  828. return static::notice(Yii::t('ctx', 'passReviewAdjustPerfSuccess'));
  829. }
  830. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  831. }
  832. /**
  833. * 审核会员业绩
  834. * @return mixed
  835. * @throws \yii\db\Exception
  836. * @throws \yii\web\HttpException
  837. */
  838. public function actionPerfAudit() {
  839. $formModel = new ChangePerfForm();
  840. $formModel->scenario = 'changeAudit';
  841. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeAudit()) {
  842. foreach ($result as $value) {
  843. $userName = Info::getUserNameByUserId($value['userId']);
  844. // Log::adminHandle('审核调整会员业绩录入数据' . $userName, 1, $value['userId'], $userName);
  845. }
  846. return static::notice(Yii::t('ctx', 'batchReviewMemberPerfCompletion'));
  847. }
  848. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  849. }
  850. /**
  851. * 删除审核会员业绩信息
  852. * @return mixed
  853. * @throws \yii\db\Exception
  854. * @throws \yii\web\HttpException
  855. */
  856. public function actionPerfAuditDelete() {
  857. $changePerfForm = new ChangePerfForm();
  858. $result = static::delete(PerfAudit::class, function ($selected) use ($changePerfForm) {
  859. $changePerfForm->beforeDelete($selected);
  860. // Log::adminHandle('删除审核会员余额信息');
  861. }, function ($selected) use ($changePerfForm) {
  862. $changePerfForm->delete($selected);
  863. // Log::adminHandle('删除审核会员余额信息');
  864. }, true);
  865. return $result;
  866. }
  867. /**
  868. * 交易类型管理
  869. * @return mixed
  870. * @throws \yii\web\HttpException
  871. */
  872. public function actionDealType() {
  873. $condition = '';
  874. $params = [];
  875. $data = DealType::lists($condition, $params, [
  876. 'orderBy' => 'DT.IS_PRESET ASC,DT.SORT_ORDER DESC',
  877. 'from' => DealType::tableName() . ' AS DT',
  878. ]);
  879. foreach ($data['list'] as $key => $value) {
  880. $data['list'][$key]['CREATE_ADMIN_NAME'] = Admin::getAdminNameById($value['CREATE_ADMIN']);
  881. $data['list'][$key]['UPDATE_ADMIN_NAME'] = Admin::getAdminNameById($value['UPDATE_ADMIN']);
  882. }
  883. return static::notice($data);
  884. }
  885. /**
  886. * 交易类型录入
  887. * @return mixed
  888. * @throws \yii\web\HttpException
  889. */
  890. public function actionDealTypeAdd() {
  891. if (Yii::$app->request->isPost) {
  892. return parent::edit(DealTypeForm::class, Yii::t('ctx', 'transactionTypeAddSuccess'), 'add', ['add'], null, function ($form, $result) {
  893. // Log::adminHandle('交易类型录入');
  894. });
  895. }
  896. }
  897. /**
  898. * 交易类型获取
  899. * @return mixed
  900. * @throws \yii\web\HttpException
  901. */
  902. public function actionDealTypeGet() {
  903. $id = Yii::$app->request->get('id');
  904. $dealType = DealType::findOneAsArray('ID=:ID', [':ID' => $id]);
  905. if (!$dealType) {
  906. return static::notice(Yii::t('ctx', 'dataDoesNotExists'), 400); // 数据不存在
  907. }
  908. 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']]);
  909. }
  910. /**
  911. * 交易类型修改
  912. * @return mixed
  913. * @throws \yii\db\Exception
  914. * @throws \yii\web\HttpException
  915. */
  916. public function actionDealTypeEdit() {
  917. $formModel = new DealTypeForm();
  918. $formModel->scenario = 'edit';
  919. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  920. // Log::adminHandle('修改交易类型');
  921. return static::notice(Yii::t('ctx', 'modifyTransactionTypeCompleted'));
  922. }
  923. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  924. }
  925. /**
  926. * 交易类型删除
  927. * @return mixed
  928. * @throws \yii\db\Exception
  929. * @throws \yii\web\HttpException
  930. */
  931. public function actionDealTypeDelete() {
  932. return static::notice(Yii::t('ctx', 'unableDelete'), 400);
  933. $result = static::delete(DealType::class, null, function ($selected) {
  934. DealTypeForm::delete($selected);
  935. // Log::adminHandle('删除交易类型');
  936. }, true);
  937. return $result;
  938. }
  939. /**
  940. * 分页导入excel文件到待导入数据的表中
  941. * @return mixed
  942. * @throws \yii\base\Exception
  943. * @throws \yii\web\HttpException
  944. */
  945. public function actionImportChangeBalanceToExcelTable() {
  946. // 先上传到服务器文件
  947. if (\Yii::$app->request->isPost) {
  948. $excelImportId = Yii::$app->request->post('excelImportId');
  949. $rowCount = Yii::$app->request->post('rowCount');
  950. $startRow = Yii::$app->request->post('startRow');
  951. $limit = Yii::$app->request->post('limit', 1000);
  952. $errorMsg = '';
  953. try {
  954. $excel = new Excel();
  955. $result = $excel->pageImportDataFromExcel('changeBalance', $excelImportId, $rowCount, $startRow, $limit);
  956. } catch (\Exception $e) {
  957. $result = false;
  958. $errorMsg = $e->getMessage();
  959. }
  960. // 还有数据
  961. if ($result === 1) {
  962. return static::notice(['finish' => false]);
  963. } elseif ($result === 0) {
  964. return static::notice(['finish' => true]);
  965. } else {
  966. return static::notice($errorMsg, 400);
  967. }
  968. }
  969. }
  970. /**
  971. * 分页把待导入表中的数据导入到真正的数据中
  972. * @return mixed
  973. * @throws \yii\base\Exception
  974. * @throws \yii\web\HttpException
  975. */
  976. public function actionImportChangeBalance() {
  977. if (\Yii::$app->request->isPost) {
  978. $excelImportId = Yii::$app->request->post('excelImportId');
  979. $offset = Yii::$app->request->post('offset');
  980. $limit = Yii::$app->request->post('limit', 1000);
  981. $errorMsg = '';
  982. try {
  983. $excel = new Excel();
  984. $result = $excel->pageImportDataFromExcelTable('changeBalance', $excelImportId, $offset, $limit);
  985. } catch (\Exception $e) {
  986. $result = false;
  987. $errorMsg = $e->getMessage();
  988. }
  989. // 还有数据
  990. if ($result === 1) {
  991. return static::notice(['finish' => false]);
  992. } elseif ($result === 0) {
  993. return static::notice(['finish' => true]);
  994. } else {
  995. return static::notice($errorMsg, 400);
  996. }
  997. }
  998. }
  999. /**
  1000. * 历史奖金余额
  1001. * @return mixed
  1002. * @throws \yii\base\Exception
  1003. * @throws \yii\web\HttpException
  1004. */
  1005. public function actionHistoryBonus() {
  1006. $filter = $this->filterCondition([
  1007. 'USER_NAME' => 'USER_NAME',
  1008. 'REAL_NAME' => 'REAL_NAME',
  1009. 'DEC_LV_NAME' => 'DEC_LV',
  1010. 'EMP_LV_NAME' => 'EMP_LV',
  1011. 'IS_DEC' => 'IS_DEC',
  1012. // 'DEC_ROLE_NAME' => 'DEC_ROLE_ID',
  1013. 'SYSTEM_NAME' => 'SYSTEM_NAME',
  1014. 'BONUS' => 'BONUS',
  1015. // 'CF' => 'CF',
  1016. // 'LX' => 'LX',
  1017. 'WITHDRAW' => 'WITHDRAW',
  1018. // 'WITHDRAW_TAX' => 'WITHDRAW_TAX',
  1019. // 'WITHDRAW_DEDUCT' => 'WITHDRAW_DEDUCT',
  1020. 'WITHDRAW_REAL' => 'WITHDRAW_REAL',
  1021. 'WITHDRAW_FAIL' => 'WITHDRAW_FAIL',
  1022. 'USER_STATUS_NAME' => 'USER_STATUS',
  1023. 'USER_STATUS_AT' => 'USER_STATUS_AT',
  1024. // 'HIGHEST_EMP_LV_NAME' => 'HIGHEST_EMP_LV',
  1025. 'PERIOD_AT' => 'PERIOD_AT',
  1026. // 'DEC_DEC_ROLE_NAME' => 'DEC_DEC_ROLE_ID',
  1027. 'DEC_USER_NAME' => 'DEC_USER_NAME',
  1028. 'DEC_REAL_NAME' => 'DEC_REAL_NAME',
  1029. 'MOBILE' => 'MOBILE',
  1030. 'TEL' => 'TEL',
  1031. 'AREA' => [
  1032. 'FIELD' => ['PROVINCE', 'CITY', 'COUNTY'],
  1033. 'BIND' => ['PROVINCE', 'CITY', 'COUNTY'],
  1034. ],
  1035. // 'SUB_COM_NAME' => 'SUB_COM_ID',
  1036. // 'IS_DIRECT_SELLER' => 'IS_DIRECT_SELLER',
  1037. 'BACKUP_AT' => 'BACKUP_AT',
  1038. ]);
  1039. $condition = $filter['condition'];
  1040. $params = $filter['params'];
  1041. $listObj = new HistoryBonusList();
  1042. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  1043. return static::notice($data);
  1044. }
  1045. /**
  1046. * 历史奖金余额导出
  1047. * @return mixed
  1048. * @throws \yii\db\Exception
  1049. * @throws \yii\web\HttpException
  1050. */
  1051. public function actionHistoryBonusExport() {
  1052. $filter = $this->filterCondition([
  1053. 'USER_NAME' => 'USER_NAME',
  1054. 'REAL_NAME' => 'REAL_NAME',
  1055. 'DEC_LV_NAME' => 'DEC_LV',
  1056. 'EMP_LV_NAME' => 'EMP_LV',
  1057. 'IS_DEC' => 'IS_DEC',
  1058. 'DEC_ROLE_NAME' => 'DEC_ROLE_ID',
  1059. 'SYSTEM_NAME' => 'SYSTEM_NAME',
  1060. 'BONUS' => 'BONUS',
  1061. 'CF' => 'CF',
  1062. 'LX' => 'LX',
  1063. 'WITHDRAW' => 'WITHDRAW',
  1064. 'WITHDRAW_TAX' => 'WITHDRAW_TAX',
  1065. 'WITHDRAW_DEDUCT' => 'WITHDRAW_DEDUCT',
  1066. 'WITHDRAW_REAL' => 'WITHDRAW_REAL',
  1067. 'WITHDRAW_FAIL' => 'WITHDRAW_FAIL',
  1068. 'USER_STATUS_NAME' => 'USER_STATUS',
  1069. 'USER_STATUS_AT' => 'USER_STATUS_AT',
  1070. 'HIGHEST_EMP_LV_NAME' => 'HIGHEST_EMP_LV',
  1071. 'PERIOD_AT' => 'PERIOD_AT',
  1072. 'DEC_DEC_ROLE_NAME' => 'DEC_DEC_ROLE_ID',
  1073. 'DEC_USER_NAME' => 'DEC_USER_NAME',
  1074. 'DEC_REAL_NAME' => 'DEC_REAL_NAME',
  1075. 'MOBILE' => 'MOBILE',
  1076. 'TEL' => 'TEL',
  1077. 'AREA' => [
  1078. 'FIELD' => ['PROVINCE', 'CITY', 'COUNTY'],
  1079. 'BIND' => ['PROVINCE', 'CITY', 'COUNTY'],
  1080. ],
  1081. 'SUB_COM_NAME' => 'SUB_COM_ID',
  1082. 'IS_DIRECT_SELLER' => 'IS_DIRECT_SELLER',
  1083. 'BACKUP_AT' => 'BACKUP_AT',
  1084. ]);
  1085. $form = new FinanceExportForm();
  1086. $result = $form->run($filter, '历史奖金余额');
  1087. if (!$result) {
  1088. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1089. }
  1090. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1091. }
  1092. /**
  1093. * 充值列表
  1094. * @return mixed
  1095. * @throws \yii\base\Exception
  1096. * @throws \yii\web\HttpException
  1097. */
  1098. public function actionRecharge()
  1099. {
  1100. $filter = $this->filterCondition([
  1101. 'SN' => 'R.SN',
  1102. 'USER_NAME' => 'UI.USER_NAME',
  1103. 'AMOUNT' => 'R.AMOUNT',
  1104. 'AUDIT_STATUS' => 'R.AUDIT_STATUS',
  1105. 'BANK_NO' => 'R.BANK_NO',
  1106. 'CREATED_AT' => 'R.CREATED_AT',
  1107. ]);
  1108. $condition = $filter['condition'];
  1109. $params = $filter['params'];
  1110. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  1111. if (!$isSuper) {
  1112. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  1113. $adminCountry = AdminCountry::getCountry($adminId);
  1114. $quotedAdminCountry = array_map(function($item) {
  1115. return "'" . addslashes($item) . "'";
  1116. }, $adminCountry);
  1117. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  1118. }
  1119. $listObj = new RechargeList();
  1120. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  1121. return static::notice($data);
  1122. }
  1123. /**
  1124. * 提交充值申请
  1125. * @return mixed
  1126. * @throws \yii\db\Exception
  1127. * @throws \yii\web\HttpException
  1128. */
  1129. public function actionRechargeType() {
  1130. if (\Yii::$app->request->isPost) {
  1131. $formModel = new RechargeForm();
  1132. $formModel->scenario = 'updateByAdmin';
  1133. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->updateType()) {
  1134. return static::notice(Yii::t('app', 'successfully'));
  1135. } else {
  1136. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  1137. }
  1138. }
  1139. return static::notice(['type'=>['Cash', 'Credit Card', 'Direct Banking']]);
  1140. }
  1141. /**
  1142. * 充值导出
  1143. * @return mixed
  1144. * @throws \yii\db\Exception
  1145. * @throws \yii\web\HttpException
  1146. */
  1147. public function actionRechargeExport() {
  1148. $filter = $this->filterCondition([
  1149. 'SN' => 'R.SN',
  1150. 'USER_NAME' => 'UI.USER_NAME',
  1151. 'AMOUNT' => 'R.AMOUNT',
  1152. 'AUDIT_STATUS' => 'R.AUDIT_STATUS',
  1153. 'BANK_NO' => 'R.BANK_NO',
  1154. 'CREATED_AT' => 'R.CREATED_AT',
  1155. ]);
  1156. $condition = $filter['condition'];
  1157. $params = $filter['params'];
  1158. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  1159. if (!$isSuper) {
  1160. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  1161. $adminCountry = AdminCountry::getCountry($adminId);
  1162. $quotedAdminCountry = array_map(function($item) {
  1163. return "'" . addslashes($item) . "'";
  1164. }, $adminCountry);
  1165. $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
  1166. }
  1167. $form = new FinanceExportForm();
  1168. $result = $form->run(['condition' => $condition, 'params' => $params], 'Recharge'); // 充值申请
  1169. if (!$result) {
  1170. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  1171. }
  1172. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  1173. }
  1174. /**
  1175. * 改变充值状态
  1176. * @return mixed
  1177. * @throws \yii\base\Exception
  1178. * @throws \yii\db\Exception
  1179. * @throws \yii\web\HttpException
  1180. */
  1181. public function actionRechargeStatus() {
  1182. $id = Yii::$app->request->get('id');
  1183. if (Yii::$app->request->isPost) {
  1184. $formModel = new RechargeForm();
  1185. $formModel->scenario = 'statusByAdmin';
  1186. //$formModel->id = $id;
  1187. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  1188. foreach ($result['logs'] as $k => $value) {
  1189. $userName = Info::getUserNameByUserId($k);
  1190. // Log::adminHandle('为会员' . $userName . '的充值流水号为' . $value . '改变充值状态至' . Recharge::STATUS_NAME[$result['status']], 1, $k, $userName);
  1191. }
  1192. return static::notice(Yii::t('ctx', 'statusSettingSucceeded')); // 状态设置成功
  1193. } else {
  1194. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  1195. }
  1196. }
  1197. // 所有开户行
  1198. $statusArray = [
  1199. 2=>Yii::t('ctx', 'backendApiControllersFinaceRechargeStatusApprove'),
  1200. 3=>Yii::t('ctx', 'backendApiControllersFinaceRechargeStatusReject'),
  1201. ]; // 2=>'审核通过',3=>'审核拒绝'
  1202. return static::notice(['statusArray' => $statusArray]);
  1203. }
  1204. /**
  1205. * 连点操作校验码获取
  1206. * @return mixed
  1207. * @throws \yii\web\HttpException
  1208. */
  1209. public function actionMultPoint() {
  1210. $verifyCode = $this->_random(8,1);
  1211. $adminId = \Yii::$app->user->id;
  1212. if (\Yii::$app->request->isPost) {
  1213. $opType = Yii::$app->request->post('opType');
  1214. if($opType==1){
  1215. $redisName = 'balanceCode';
  1216. }elseif ($opType==2){
  1217. $redisName = 'withdrawAudit';
  1218. }
  1219. }
  1220. \Yii::$app->redis->set($redisName.'_'.$adminId,$verifyCode);
  1221. return static::notice([$redisName => $verifyCode]);
  1222. }
  1223. /**
  1224. * 生成随机数
  1225. * @param $length
  1226. * @param int $numeric
  1227. * @return string
  1228. */
  1229. private function _random($length, $numeric = 0) {
  1230. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  1231. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  1232. $hash = '';
  1233. $max = strlen($seed) - 1;
  1234. for ($i = 0; $i < $length; $i++) {
  1235. $hash .= $seed[mt_rand(0, $max)];
  1236. }
  1237. return $hash;
  1238. }
  1239. }