FinanceController.php 54 KB

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