FinanceController.php 53 KB

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