FinanceController.php 51 KB

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