FinanceController.php 50 KB

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