FinanceController.php 54 KB

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