FinanceController.php 55 KB

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