ReconsumeController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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\ReconsumeExportForm;
  11. use backendApi\modules\v1\models\lists\reconsume\FlowList;
  12. use backendApi\modules\v1\models\lists\reconsume\PoolList;
  13. use backendApi\modules\v1\models\lists\reconsume\ReconsumeAuditList;
  14. use common\helpers\Cache;
  15. use common\helpers\Form;
  16. use common\helpers\Log;
  17. use common\helpers\Tool;
  18. use common\helpers\user\Reconsume;
  19. use common\helpers\user\Info;
  20. use common\libs\export\module\ReconsumeExport;
  21. use common\models\forms\ReconsumeForm;
  22. use common\models\Period;
  23. use common\models\ReconsumeAudit;
  24. use common\models\ReconsumePool;
  25. use common\models\ReconsumePoolFlow;
  26. use common\models\User;
  27. use common\models\UserInfo;
  28. use Yii;
  29. class ReconsumeController extends BaseController {
  30. public $modelClass = ReconsumePool::class;
  31. /**
  32. * 复销池余额列表
  33. * @return mixed
  34. * @throws \yii\base\Exception
  35. * @throws \yii\web\HttpException
  36. */
  37. public function actionPoolList() {
  38. $filter = $this->filterCondition([
  39. 'userIds' => 'USER_ID',
  40. 'UNUSED_PV' => 'UNUSED_PV',
  41. 'UNUSED_MONTH' => 'UNUSED_MONTH',
  42. ]);
  43. $condition = $filter['condition'];
  44. $params = $filter['params'];
  45. $listObj = new PoolList();
  46. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  47. return static::notice($data);
  48. }
  49. /**
  50. * 复销池余额列表导出
  51. * @return mixed
  52. * @throws \yii\db\Exception
  53. * @throws \yii\web\HttpException
  54. */
  55. public function actionPoolListExport() {
  56. $filter = $this->filterCondition([
  57. 'userIds' => 'USER_ID',
  58. 'UNUSED_PV' => 'UNUSED_PV',
  59. 'UNUSED_MONTH' => 'UNUSED_MONTH',
  60. ]);
  61. $form = new ReconsumeExportForm();
  62. $result = $form->run($filter, '复销池余额列表');
  63. if (!$result) {
  64. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  65. }
  66. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  67. }
  68. /**
  69. * 复销审核列表
  70. * @return mixed
  71. * @throws \yii\base\Exception
  72. * @throws \yii\web\HttpException
  73. */
  74. public function actionChangeAuditList() {
  75. $filter = $this->filterCondition([
  76. 'userIds' => 'UI.USER_ID',
  77. 'filterStatus' => 'RA.AUDIT_STATUS',
  78. 'TYPE_NAME' => 'RA.TYPE',
  79. 'CHANGE_PV' => 'RA.CHANGE_PV',
  80. 'CHANGE_MONTH' => 'RA.CHANGE_MONTH',
  81. 'REMARK_IS_SHOW' => 'RA.REMARK_IS_SHOW',
  82. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  83. 'AUDIT_ADMIN_NAME' => 'ADMA.ADMIN_NAME',
  84. 'CREATED_AT' => 'RA.CREATED_AT',
  85. 'AUDITED_AT' => 'RA.AUDITED_AT',
  86. 'CREATE_REMARK' => 'RA.CREATE_REMARK',
  87. ]);
  88. $condition = $filter['condition'];
  89. $params = $filter['params'];
  90. $listObj = new ReconsumeAuditList();
  91. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  92. return static::notice($data);
  93. }
  94. /**
  95. * 复销余额调整审核列表导出
  96. * @return mixed
  97. * @throws \yii\db\Exception
  98. * @throws \yii\web\HttpException
  99. */
  100. public function actionChangeAuditListExport() {
  101. $filter = $this->filterCondition([
  102. 'userIds' => 'UI.USER_ID',
  103. 'filterStatus' => 'RA.AUDIT_STATUS',
  104. 'TYPE_NAME' => 'RA.TYPE',
  105. 'CHANGE_PV' => 'RA.CHANGE_PV',
  106. 'CHANGE_MONTH' => 'RA.CHANGE_MONTH',
  107. 'REMARK_IS_SHOW' => 'RA.REMARK_IS_SHOW',
  108. 'CREATE_ADMIN_NAME' => 'ADMC.ADMIN_NAME',
  109. 'AUDIT_ADMIN_NAME' => 'ADMU.ADMIN_NAME',
  110. 'CREATED_AT' => 'RA.CREATED_AT',
  111. 'AUDITED_AT' => 'RA.AUDITED_AT',
  112. 'CREATE_REMARK' => 'RA.CREATE_REMARK',
  113. ]);
  114. $form = new ReconsumeExportForm();
  115. $result = $form->run($filter, '复销余额调整审核列表');
  116. if (!$result) {
  117. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  118. }
  119. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  120. }
  121. /**
  122. * 申请调整复销余额
  123. * @return mixed
  124. * @throws \yii\base\InvalidConfigException
  125. * @throws \yii\httpclient\Exception
  126. * @throws \yii\web\HttpException
  127. *
  128. */
  129. public function actionChangeAuditAdd() {
  130. $userName = Yii::$app->request->get('userName');
  131. if (Yii::$app->request->isPost) {
  132. return parent::edit(ReconsumeForm::class, '申请调整复销余额成功', 'changeAdd', ['changeAdd'], null, function ($form, $result) {
  133. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  134. // Log::adminHandle('申请为' . $user['USER_NAME'] . '调整复销余额', 1, $result['USER_ID'], $user['USER_NAME']);
  135. });
  136. }
  137. if (!$userName) {
  138. return static::notice('会员不正确');
  139. }
  140. // 获取复销的可用余额和剩余次数
  141. $reConsumePool = Reconsume::getUserReconsumePoolByUserName($userName);
  142. return static::notice($reConsumePool);
  143. }
  144. /**
  145. * 复销变动信息
  146. * @return mixed
  147. * @throws \yii\base\Exception
  148. * @throws \yii\web\HttpException
  149. */
  150. public function actionChangeAuditGet() {
  151. $id = Yii::$app->request->get('id');
  152. $reconsumAudit = ReconsumeAudit::findOneAsArray('ID=:ID', [':ID' => $id]);
  153. if (!$reconsumAudit) {
  154. return static::notice('The data does not exist', 400); // 数据不存在
  155. }
  156. $reconsumAudit['BASE_INFO'] = Info::baseInfoZh($reconsumAudit['USER_ID']);
  157. $reConsumePool = Reconsume::getUserReconsumePool($reconsumAudit['USER_ID']);
  158. return static::notice(['id' => $reconsumAudit['ID'], 'baseInfo' => $reconsumAudit['BASE_INFO'], 'balance' => $reConsumePool, 'type' => $reconsumAudit['CHANGE_PV'] != 0 ? ReconsumeForm::TYPE_BALANCE : ReconsumeForm::TYPE_MONTH, 'changePv' => Tool::formatPrice($reconsumAudit['CHANGE_PV']), 'changeMonth' => $reconsumAudit['CHANGE_MONTH'], 'remark' => $reconsumAudit['CREATE_REMARK'], 'isShow' => $reconsumAudit['REMARK_IS_SHOW']]);
  159. }
  160. /**
  161. * 修改复销月录入数据
  162. * @return mixed
  163. * @throws \yii\db\Exception
  164. * @throws \yii\web\HttpException
  165. */
  166. public function actionChangeAuditEdit() {
  167. $formModel = new ReconsumeForm();
  168. $formModel->scenario = 'edit';
  169. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  170. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  171. // Log::adminHandle('修改' . $user['USER_NAME'] . '调整复销余额录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  172. return static::notice('修改调整复销余额录入数据完成');
  173. }
  174. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  175. }
  176. /**
  177. * 审核通过复销月录入数据
  178. * @return mixed
  179. * @throws \yii\db\Exception
  180. * @throws \yii\web\HttpException
  181. */
  182. public function actionChangeAuditPass() {
  183. $formModel = new ReconsumeForm();
  184. $formModel->scenario = 'pass';
  185. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->pass()) {
  186. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  187. // Log::adminHandle('审核通过' . $user['USER_NAME'] . '调整复销余额录入数据', 1, $result['USER_ID'], $user['USER_NAME']);
  188. return static::notice('审核通过调整复销池余额完成');
  189. }
  190. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  191. }
  192. /**
  193. * 审核
  194. * @return mixed
  195. * @throws \yii\base\InvalidConfigException
  196. * @throws \yii\db\Exception
  197. * @throws \yii\httpclient\Exception
  198. * @throws \yii\web\HttpException
  199. */
  200. public function actionChangeAudit() {
  201. $formModel = new ReconsumeForm();
  202. $formModel->scenario = 'changeAudit';
  203. if ($formModel->load(Yii::$app->request->post(), '') && $result = $formModel->changeAudit()) {
  204. return static::notice('批量审核/拒绝调整复销池余额完成');
  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 actionChangeAuditDelete() {
  215. $reconsumeForm = new ReconsumeForm();
  216. $result = static::delete(ReconsumeAudit::class, function ($selected) use ($reconsumeForm) {
  217. $reconsumeForm->beforeDelete($selected);
  218. // Log::adminHandle('删除审核会员余额信息');
  219. }, function ($selected) use ($reconsumeForm) {
  220. $reconsumeForm->delete($selected);
  221. // Log::adminHandle('删除审核会员余额信息');
  222. }, true);
  223. return $result;
  224. }
  225. /**
  226. * 扣除复销审核列表
  227. * @return mixed
  228. * @throws \yii\web\HttpException
  229. */
  230. public function actionDeductAuditList() {
  231. $filter = $this->filterCondition([
  232. 'userIds' => 'RA.USER_ID',
  233. 'filterStatus' => 'RA.AUDIT_STATUS',
  234. ]);
  235. $condition = $filter['condition'];
  236. $params = $filter['params'];
  237. $condition .= ' AND RA.TYPE=:TYPE ';
  238. $params[':TYPE'] = ReconsumeAudit::TYPE_RECONSUME;
  239. $data = ReconsumeAudit::lists($condition, $params, [
  240. 'from' => ReconsumeAudit::tableName() . ' AS RA',
  241. 'orderBy' => 'RA.CREATED_AT DESC',
  242. ]);
  243. $auditStatus = array_column(\Yii::$app->params['auditStatus'], null, 'value');
  244. foreach ($data['list'] as $key => $value) {
  245. $data['list'][$key]['BASE_INFO'] = Info::baseInfoZh($value['USER_ID']);
  246. $data['list'][$key]['CREATE_ADMIN_NAME'] = Admin::getAdminNameById($value['CREATE_ADMIN']);
  247. $data['list'][$key]['AUDIT_ADMIN_NAME'] = Admin::getAdminNameById($value['AUDIT_ADMIN']);
  248. $data['list'][$key]['STATUS_NAME'] = $auditStatus[$value['AUDIT_STATUS']]['label'];
  249. }
  250. return static::notice($data);
  251. }
  252. /**
  253. * 申请扣除月复销
  254. * @return mixed
  255. * @throws \yii\base\InvalidConfigException
  256. * @throws \yii\db\Exception
  257. * @throws \yii\httpclient\Exception
  258. * @throws \yii\web\HttpException
  259. */
  260. public function actionDeductAuditAdd() {
  261. $userName = Yii::$app->request->get('userName');
  262. if (Yii::$app->request->isPost) {
  263. return parent::edit(ReconsumeForm::class, '扣除月复销成功', 'deductReConsumeAdd', ['deductReConsumeAdd'], null, function ($form, $result) {
  264. //$user = User::getBaseInfoFromRedis($result['USER_ID']);
  265. // Log::adminHandle('为' . $user['USER_NAME'] . '扣除月复销', 1, $result['USER_ID'], $user['USER_NAME']);
  266. });
  267. }
  268. if ($userName) {
  269. // 获取复销的可用余额和剩余次数
  270. $reConsumePool = Reconsume::getUserReconsumePoolByUserName($userName);
  271. $sysConfig = Cache::getSystemConfig();
  272. $deductPv = $sysConfig['reConsumePerf']['VALUE'];
  273. return static::notice(['balance'=>$reConsumePool,'deductPv'=>$deductPv]);
  274. }else{
  275. $period = Period::instance();
  276. $year = $period->getNowYear();
  277. $sentMaxPeriodNum = Period::sentMaxPeriodNum();
  278. $month = $period->getMonth($sentMaxPeriodNum);
  279. return static::notice(['year'=>$year,'month'=>$month]);
  280. }
  281. }
  282. /**
  283. * 扣除月复销审核
  284. * @return mixed
  285. * @throws \yii\web\HttpException
  286. */
  287. public function actionDeductAudit() {
  288. $id = Yii::$app->request->get('id', 0);
  289. if (Yii::$app->request->isPost) {
  290. return parent::edit(ReconsumeForm::class, '审核完成', 'deductReConsumeAudit', ['deductReConsumeAudit'], function ($formModel) use ($id) {
  291. $formModel->id = $id;
  292. }, function ($form, $result) {
  293. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  294. // Log::adminHandle('审核为' . $user['USER_NAME'] . '扣除月复销', 1, $result['USER_ID'], $user['USER_NAME']);
  295. });
  296. }
  297. }
  298. /**
  299. * 扣复销(合格不合格)
  300. * @return mixed
  301. * @throws \yii\web\HttpException
  302. */
  303. public function actionDeduct() {
  304. if (Yii::$app->request->isPost) {
  305. return parent::edit(ReconsumeForm::class, '扣除成功', 'deductReConsume', ['deductReConsume'], null, function ($form, $result) {
  306. if ($form->isPass) {
  307. $handle = '合格';
  308. } else {
  309. $handle = '不合格';
  310. }
  311. $user = User::getBaseInfoFromRedis($result['USER_ID']);
  312. // Log::adminHandle('为' . $user['USER_NAME'] . '扣除月复销' . $handle, 1, $result['USER_ID'], $user['USER_NAME']);
  313. });
  314. }
  315. }
  316. /**
  317. * 复销流水
  318. * @return mixed
  319. * @throws \yii\base\Exception
  320. * @throws \yii\web\HttpException
  321. */
  322. public function actionFlowList() {
  323. $filter = $this->filterCondition([
  324. 'userIds' => 'USER_ID',
  325. 'filterStatus' => 'RECONSUME_POOL_TYPE',
  326. 'RECONSUME_POOL_SN' => 'RECONSUME_POOL_SN',
  327. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  328. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  329. 'LAST_STATUS_NAME' => 'LAST_STATUS',
  330. 'DEAL_TYPE_NAME' => 'DEAL_TYPE',
  331. 'DEDUCT_PV' => 'DEDUCT_PV',
  332. 'UNUSED_PV' => 'UNUSED_PV',
  333. 'DEDUCT_MONTH' => 'DEDUCT_MONTH',
  334. 'UNUSED_MONTH' => 'UNUSED_MONTH',
  335. 'CALC_MONTH' => 'CALC_MONTH',
  336. 'CREATED_AT' => 'CREATED_AT',
  337. 'REMARK' => 'REMARK',
  338. 'ADMIN_NAME' => 'ADMIN_NAME',
  339. ]);
  340. $condition = $filter['condition'];
  341. $params = $filter['params'];
  342. $listObj = new FlowList();
  343. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  344. return static::notice($data);
  345. }
  346. /**
  347. * 复销流水导出
  348. * @return mixed
  349. * @throws \yii\db\Exception
  350. * @throws \yii\web\HttpException
  351. */
  352. public function actionFlowListExport() {
  353. $filter = $this->filterCondition([
  354. 'userIds' => 'USER_ID',
  355. 'filterStatus' => 'RECONSUME_POOL_TYPE',
  356. 'RECONSUME_POOL_SN' => 'RECONSUME_POOL_SN',
  357. 'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
  358. 'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
  359. 'LAST_STATUS_NAME' => 'LAST_STATUS',
  360. 'DEAL_TYPE_NAME' => 'DEAL_TYPE',
  361. 'DEDUCT_PV' => 'DEDUCT_PV',
  362. 'UNUSED_PV' => 'UNUSED_PV',
  363. 'DEDUCT_MONTH' => 'DEDUCT_MONTH',
  364. 'UNUSED_MONTH' => 'UNUSED_MONTH',
  365. 'CALC_MONTH' => 'CALC_MONTH',
  366. 'CREATED_AT' => 'CREATED_AT',
  367. 'REMARK' => 'REMARK',
  368. 'ADMIN_NAME' => 'ADMIN_NAME',
  369. ]);
  370. $form = new ReconsumeExportForm();
  371. $result = $form->run($filter, '复销流水列表');
  372. if (!$result) {
  373. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  374. }
  375. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  376. }
  377. /**
  378. * 不能扣除复销的月份
  379. * @return array|\yii\db\ActiveRecord[]
  380. */
  381. public function actionCantDeductMonth(){
  382. $userName = Yii::$app->request->get('userName');
  383. $year = Yii::$app->request->get('year');
  384. $userId = Info::getUserIdByUserName($userName);
  385. return Reconsume::cantDeductMonth($userId, $year);
  386. }
  387. /**
  388. * 流水交易类型
  389. * @return mixed
  390. * @throws \yii\web\HttpException
  391. */
  392. public function actionGetFlowDealType(){
  393. return static::notice(['dealTypes'=>Reconsume::TYPE]);
  394. }
  395. }