ChangePerfForm.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <?php
  2. namespace common\models\forms;
  3. use common\components\Model;
  4. use common\helpers\Date;
  5. use common\helpers\Form;
  6. use common\helpers\Tool;
  7. use common\helpers\user\Balance;
  8. use common\helpers\user\Info;
  9. use common\libs\logging\operate\AdminOperate;
  10. use common\models\BalanceAudit;
  11. use common\models\PerfAudit;
  12. use common\models\PerfMonth;
  13. use common\models\PerfPeriod;
  14. use common\models\Period;
  15. use common\models\User;
  16. use common\models\UserBonus;
  17. use common\models\UserInfo;
  18. use common\models\UserPerf;
  19. use common\models\Withdraw;
  20. use yii\base\Exception;
  21. use yii\db\Expression;
  22. /**
  23. * Login form
  24. */
  25. class ChangePerfForm extends Model {
  26. public $id;
  27. public $selected;
  28. public $periodNum;
  29. public $perfType;
  30. public $userName;
  31. public $location;
  32. public $amount;
  33. public $remark;
  34. public $auditStatus;
  35. private $_periodNum;
  36. private $_userId;
  37. private $_locationField;
  38. private $_model;
  39. public function init() {
  40. parent::init();
  41. $this->adminOperateLogger = new AdminOperate([
  42. 'fetchClass' => PerfAudit::class,
  43. ]);
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function rules() {
  49. return [
  50. [['id', 'selected', 'userName', 'perfType', 'location', 'amount', 'remark', 'auditStatus'], 'trim'],
  51. [['id', 'userName', 'perfType', 'location', 'amount', 'remark', 'auditStatus'], 'required'],
  52. [['id'], 'exist', 'targetClass' => PerfAudit::class, 'targetAttribute' => 'ID', 'message' => '该申请不存在'],
  53. [['id'], 'initModel'],
  54. [['userName'], 'isUserName'],
  55. //[['periodNum'], 'isPeriodNum'],
  56. [['perfType'], 'isPerfType'],
  57. [['location'], 'isLocation'],
  58. [['amount'], 'fullPrice'],
  59. [['amount'], 'isAmount'],
  60. [['auditStatus'], 'isStatus'],
  61. [['selected'], 'isSelected'],
  62. ];
  63. }
  64. /**
  65. * 指定场景
  66. * @return array
  67. */
  68. public function scenarios() {
  69. $parentScenarios = parent::scenarios();
  70. $customScenarios = [
  71. 'add' => ['userName', 'perfType', 'location', 'amount', 'remark'],
  72. 'changeAudit' => ['selected', 'remark', 'auditStatus'],
  73. 'pass' => ['id', 'perfType', 'location', 'amount', 'remark', 'auditStatus'],
  74. ];
  75. return array_merge($parentScenarios, $customScenarios);
  76. }
  77. /**
  78. * @return array
  79. */
  80. public function attributeLabels() {
  81. return [
  82. 'id' => '申请的ID',
  83. 'userName' => '会员编号',
  84. 'location' => '区域',
  85. 'amount' => '变动数额',
  86. 'remark' => '备注',
  87. 'auditStatus' => '状态',
  88. ];
  89. }
  90. /**
  91. * 初始化model
  92. */
  93. public function initModel($attribute) {
  94. $model = $this->_model = PerfAudit::findOne(['ID' => $this->id]);
  95. $this->_userId = $model->USER_ID;
  96. if ($model->AUDIT_STATUS > \Yii::$app->params['auditStatus']['un']['value']) {
  97. $this->addError($attribute, '该申请已经被审核,不能重复审核');
  98. }
  99. }
  100. /**
  101. * 设置userId
  102. * @param $attribute
  103. */
  104. public function isUserName($attribute) {
  105. $this->_userId = Info::getUserIdByUserName($this->userName);
  106. if ($this->_userId) {
  107. // 如果该会员已经存在一个待审核的申请,直接提示错误
  108. if (PerfAudit::find()->where('USER_ID=:USER_ID AND AUDIT_STATUS=:AUDIT_STATUS', [':USER_ID' => $this->_userId, ':AUDIT_STATUS' => \Yii::$app->params['auditStatus']['un']['value']])->exists()) {
  109. $this->addError($attribute, '该会员审核列表中如果有待审记录,需等待待审核记录审核后才可提交');
  110. }
  111. } else {
  112. $this->addError($attribute, '会员不存在');
  113. }
  114. }
  115. /**
  116. * 期数是否符合条件
  117. * @param $attribute
  118. */
  119. public function isPeriodNum($attribute) {
  120. $period = Period::instance();
  121. if (!$period->isSent($this->periodNum)) {
  122. $this->addError($attribute, '该期【' . $this->periodNum . '】未挂网,无法调整');
  123. }
  124. 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' => $this->periodNum + 1, ':END_PERIOD_NUM' => $this->periodNum + 1])->count() == 1) {
  125. $this->addError($attribute, '下一期【' . ($this->periodNum + 1) . '】已挂网,该期无法调整');
  126. }
  127. }
  128. /**
  129. * 类型是否符合条件
  130. * @param $attribute
  131. */
  132. public function isPerfType($attribute) {
  133. if (!in_array($this->perfType, array_keys(PerfAudit::CHANGE_PERF_TYPE))) {
  134. $this->addError($attribute, '调整类型不正确');
  135. }
  136. $this->_periodNum = Period::sentMaxPeriodNum();
  137. }
  138. /**
  139. * 校验区域
  140. * @param $attribute
  141. */
  142. public function isLocation($attribute) {
  143. if ($this->perfType==PerfAudit::PERF_TYPE_PV && !in_array($this->location, [1, 2, 3, 4, 5])) {
  144. $this->addError($attribute, '区位不正确');
  145. }
  146. if ($this->perfType==PerfAudit::PERF_TYPE_SURPLUS && !in_array($this->location, [1, 2, 3, 4, 5, 6])) {
  147. $this->addError($attribute, '区位不正确');
  148. }
  149. }
  150. /**
  151. * 金额是否正确
  152. * @param $attribute
  153. */
  154. public function isAmount($attribute) {
  155. if ($this->amount == 0) $this->addError($attribute, '变动数额不能为0');
  156. if ($this->perfType == PerfAudit::PERF_TYPE_PV) {
  157. $userPerf = UserPerf::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $this->_userId]);
  158. if ($this->amount < 0 && (abs($this->amount) > $userPerf['PV_' . $this->location . 'L'])) {
  159. $this->addError('scenario', '该会员该区域的数额不足');
  160. }
  161. } elseif ($this->perfType == PerfAudit::PERF_TYPE_SURPLUS) {
  162. $perfPeriod = PerfPeriod::findOneAsArray('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [':USER_ID' => $this->_userId, ':PERIOD_NUM' => $this->_periodNum]);
  163. if($this->location==6){
  164. if ($this->amount < 0 && (abs($this->amount) > $perfPeriod['SURPLUS_LS'])) {
  165. $this->addError('scenario', '该会员当期该区域剩余数额不足');
  166. }
  167. }else {
  168. if ($this->amount < 0 && (abs($this->amount) > $perfPeriod['SURPLUS_' . $this->location . 'L'])) {
  169. $this->addError('scenario', '该会员当期该区域剩余数额不足');
  170. }
  171. }
  172. }
  173. }
  174. /**
  175. * 校验状态
  176. * @param $attribute
  177. */
  178. public function isStatus($attribute) {
  179. // 获取当前提现单的状态
  180. $oneData = PerfAudit::findOneAsArray(['ID' => $this->id]);
  181. switch ($this->auditStatus) {
  182. case 'un':
  183. $this->addError($attribute, '不能设置为待审核状态' . $this->auditStatus);
  184. break;
  185. case 'true':
  186. if ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['true']['value']) {
  187. $this->addError($attribute, '已经审核通过不能重复审核');
  188. } elseif ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['reject']['value']) {
  189. $this->addError($attribute, '已经审核拒绝不能重复审核');
  190. }
  191. break;
  192. case 'reject':
  193. if ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['true']['value']) {
  194. $this->addError($attribute, '已经审核通过不能重复审核');
  195. } elseif ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['reject']['value']) {
  196. $this->addError($attribute, '已经审核拒绝不能重复审核');
  197. }
  198. break;
  199. default:
  200. $this->addError($attribute, '状态参数有误');
  201. }
  202. }
  203. /**
  204. * 批量数据
  205. * @param $attributes
  206. */
  207. public function isSelected($attributes) {
  208. if (!$this->selected) {
  209. $this->addError($attributes, '必须选择一条数据');
  210. }
  211. if (!is_array($this->selected)) {
  212. $this->selected = [$this->selected];
  213. }
  214. }
  215. /**
  216. * 添加变动申请
  217. * @return BalanceAudit|null
  218. * @throws \yii\db\Exception
  219. */
  220. public function add() {
  221. if (!$this->validate()) {
  222. return null;
  223. }
  224. $db = \Yii::$app->db;
  225. $transaction = $db->beginTransaction();
  226. try {
  227. // 添加申请
  228. $model = new PerfAudit();
  229. $model->USER_ID = $this->_userId;
  230. $model->PERF_TYPE = $this->perfType;
  231. $model->PERF_LOCATION = $this->location;
  232. $model->PERIOD_NUM = $this->_periodNum;
  233. $model->AMOUNT = $this->amount;
  234. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['un']['value'];
  235. $model->CREATE_ADMIN = \Yii::$app->user->id;
  236. $model->REMARK = $this->remark;
  237. $model->CREATED_AT = Date::nowTime();
  238. if (!$model->save()) {
  239. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  240. }
  241. $transaction->commit();
  242. } catch (Exception $e) {
  243. $transaction->rollBack();
  244. $this->addError('add', $e->getMessage());
  245. return null;
  246. }
  247. // 记录日志
  248. $this->adminOperateLogger->fetchClass = PerfAudit::class;
  249. $this->adminOperateLogger->afterInsert($model)->clean()->save([
  250. 'optType' => '申请调整会员业绩',
  251. 'userId' => $model->USER_ID,
  252. 'userName' => Info::getUserNameByUserId($model->USER_ID),
  253. 'remark' => $model->REMARK,
  254. ]);
  255. return $model;
  256. }
  257. /**
  258. * 管理员审核状态
  259. * @return BalanceAudit|null
  260. * @throws \yii\db\Exception
  261. */
  262. /*public function changeStatus() {
  263. if (!$this->validate()) {
  264. return null;
  265. }
  266. $db = \Yii::$app->db;
  267. $transaction = $db->beginTransaction();
  268. try {
  269. $model = $this->_model;
  270. if ($this->auditStatus == 'reject') {
  271. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['reject']['value'];
  272. } elseif ($this->auditStatus == 'true') {
  273. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['true']['value'];
  274. }
  275. $model->AUDIT_ADMIN = \Yii::$app->user->id;
  276. $model->AUDITED_AT = Date::nowTime();
  277. if (!$model->save()) {
  278. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  279. }
  280. // 如果是审核通过状态改变会员的业绩
  281. if ($this->auditStatus == 'true') {
  282. UserPerf::updateAllCounters([$this->_locationField => $this->amount], 'USER_ID=:USER_ID', [':USER_ID' => $model['USER_ID']]);
  283. }
  284. $transaction->commit();
  285. } catch (Exception $e) {
  286. $transaction->rollBack();
  287. $this->addError('status', $e->getMessage());
  288. return null;
  289. }
  290. return $model;
  291. }*/
  292. /**
  293. * 审核通过
  294. * @return null
  295. * @throws \yii\db\Exception
  296. */
  297. public function pass() {
  298. if (!$this->validate()) {
  299. return null;
  300. }
  301. // 日志记录操作前的数据
  302. $beforeData = UserPerf::getPvByUserId($this->_userId);
  303. $this->adminOperateLogger->fetchClass = UserPerf::class;
  304. $this->adminOperateLogger->beforeUpdate($beforeData);
  305. $perfData = $this->adminOperateLogger->saveBeforeContent;
  306. $beforeData = PerfPeriod::getPeriodSurplusPerf($this->_model->PERIOD_NUM,$this->_userId);
  307. $this->adminOperateLogger->fetchClass = PerfPeriod::class;
  308. $this->adminOperateLogger->beforeUpdate($beforeData);
  309. $periodData = $this->adminOperateLogger->saveBeforeContent;
  310. $this->adminOperateLogger->saveBeforeContent=array_merge($perfData,$periodData);
  311. $db = \Yii::$app->db;
  312. $transaction = $db->beginTransaction();
  313. try {
  314. $model = $this->_model;
  315. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus'][$this->auditStatus]['value'];
  316. $model->AUDIT_ADMIN = \Yii::$app->user->id;
  317. $model->AMOUNT = $this->amount;
  318. $model->REMARK = $this->remark;
  319. $model->AUDITED_AT = Date::nowTime();
  320. $perfModel = UserPerf::findOne(['USER_ID' => $model->USER_ID]);
  321. $periodModel = PerfPeriod::findOne(['USER_ID' => $model->USER_ID, 'PERIOD_NUM' => $model->PERIOD_NUM]);
  322. $perfBefore = 0;
  323. $perfAfter = 0;
  324. // 如果是审核通过状态
  325. if ($this->auditStatus == 'true') {
  326. if ($model->PERF_TYPE == PerfAudit::PERF_TYPE_PV) {
  327. //给上月累计
  328. $period = Period::instance();
  329. $lastMonth = $period->getLastMonth();
  330. PerfMonth::updateAll(['PV_' . $model->PERF_LOCATION . 'L_TOTAL'=> new Expression('PV_' . $model->PERF_LOCATION . 'L_TOTAL+'.$model->AMOUNT)],'USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH',[':USER_ID'=>$model->USER_ID,':CALC_MONTH'=>$lastMonth['yearMonth']]);
  331. $locaionField = 'PV_' . $model->PERF_LOCATION . 'L';
  332. $perfBefore = $perfModel->$locaionField;
  333. $perfAfter = $perfModel->$locaionField + $model->AMOUNT;
  334. $perfModel->$locaionField = $perfAfter;
  335. if (!$perfModel->save()) {
  336. throw new Exception(Form::formatErrorsForApi($perfModel->getErrors()));
  337. }
  338. } elseif ($model->PERF_TYPE == PerfAudit::PERF_TYPE_SURPLUS) {
  339. if($model->PERF_LOCATION==6){
  340. $locaionField = 'SURPLUS_LS';
  341. }else{
  342. $locaionField = 'SURPLUS_' . $model->PERF_LOCATION . 'L';
  343. }
  344. $perfBefore = $periodModel->$locaionField;
  345. $perfAfter = $periodModel->$locaionField + $model->AMOUNT;
  346. $periodModel->$locaionField = $perfAfter;
  347. if (!$periodModel->save()) {
  348. throw new Exception(Form::formatErrorsForApi($periodModel->getErrors()));
  349. }
  350. }
  351. }
  352. $model->PV_1L = $perfModel->PV_1L;
  353. $model->PV_2L = $perfModel->PV_2L;
  354. $model->PV_3L = $perfModel->PV_3L;
  355. $model->PV_4L = $perfModel->PV_4L;
  356. $model->PV_5L = $perfModel->PV_5L;
  357. $model->SURPLUS_1L = $periodModel->SURPLUS_1L;
  358. $model->SURPLUS_2L = $periodModel->SURPLUS_2L;
  359. $model->SURPLUS_3L = $periodModel->SURPLUS_3L;
  360. $model->SURPLUS_4L = $periodModel->SURPLUS_4L;
  361. $model->SURPLUS_5L = $periodModel->SURPLUS_5L;
  362. $model->SURPLUS_LS = $periodModel->SURPLUS_LS;
  363. $model->PERF_BEFORE = $perfBefore;
  364. $model->PERF_AFTER = $perfAfter;
  365. if (!$model->save()) {
  366. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  367. }
  368. $transaction->commit();
  369. } catch (Exception $e) {
  370. $transaction->rollBack();
  371. $this->addError('pass', $e->getMessage());
  372. return null;
  373. }
  374. // 记录日志
  375. $beforeData = UserPerf::getPvByUserId($this->_userId);
  376. $this->adminOperateLogger->fetchClass = UserPerf::class;
  377. $this->adminOperateLogger->afterUpdate($beforeData);
  378. $perfData = $this->adminOperateLogger->saveAfterContent;
  379. $beforeData = PerfPeriod::getPeriodSurplusPerf($this->_model->PERIOD_NUM,$this->_userId);
  380. $this->adminOperateLogger->fetchClass = PerfPeriod::class;
  381. $this->adminOperateLogger->afterUpdate($beforeData);
  382. $periodData = $this->adminOperateLogger->saveAfterContent;
  383. $this->adminOperateLogger->saveAfterContent=array_merge($perfData,$periodData);
  384. $this->adminOperateLogger->clean()->save([
  385. 'optType' => '审核通过会员业绩',
  386. 'userId' => $model->USER_ID,
  387. 'userName' => Info::getUserNameByUserId($model->USER_ID),
  388. 'remark' => $model->REMARK,
  389. ]);
  390. return $model;
  391. }
  392. /**
  393. * 修改审核状态
  394. * @return array|null
  395. * @throws \yii\db\Exception
  396. */
  397. public function changeAudit() {
  398. if (!$this->validate()) {
  399. return null;
  400. }
  401. $db = \Yii::$app->db;
  402. $transaction = $db->beginTransaction();
  403. $logs = [];
  404. $uids=[];
  405. if($this->auditStatus=='true'){
  406. foreach ($this->selected as $select) {
  407. $oneBalanceAudit = PerfAudit::findOneAsArray('ID=:ID',[':ID'=>$select],'USER_ID');
  408. $uids[]=$oneBalanceAudit['USER_ID'];
  409. }
  410. }
  411. try {
  412. if($this->auditStatus=='true'){
  413. $this->adminOperateLogger->fetchClass = UserPerf::class;
  414. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($uids, 'USER_ID');
  415. $perfData = $this->adminOperateLogger->saveBeforeContent;
  416. $this->adminOperateLogger->fetchClass = PerfPeriod::class;
  417. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($uids, 'USER_ID');
  418. $periodData = $this->adminOperateLogger->saveBeforeContent;
  419. $this->adminOperateLogger->saveBeforeContent=Tool::mergeArrayWithKey($perfData,$periodData);
  420. }else{
  421. $this->adminOperateLogger->fetchClass = PerfAudit::class;
  422. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->selected, 'ID');
  423. }
  424. foreach ($this->selected as $select) {
  425. $model = PerfAudit::findOne(['ID' => $select]);
  426. if ($model->AUDIT_STATUS > \Yii::$app->params['auditStatus']['un']['value']) continue;
  427. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus'][$this->auditStatus]['value'];
  428. $model->AUDIT_ADMIN = \Yii::$app->user->id;
  429. $model->REMARK = $this->remark;
  430. $model->AUDITED_AT = Date::nowTime();
  431. $perfModel = UserPerf::findOne(['USER_ID' => $model->USER_ID]);
  432. $periodModel = PerfPeriod::findOne(['USER_ID' => $model->USER_ID, 'PERIOD_NUM' => $model->PERIOD_NUM]);
  433. $perfBefore = 0;
  434. $perfAfter = 0;
  435. if ($model->AUDIT_STATUS == \Yii::$app->params['auditStatus']['true']['value']) {
  436. if ($model->PERF_TYPE == PerfAudit::PERF_TYPE_PV) {
  437. //给上月累计
  438. $period = Period::instance();
  439. $lastMonth = $period->getLastMonth();
  440. PerfMonth::updateAll(['PV_' . $model->PERF_LOCATION . 'L_TOTAL'=> new Expression('PV_' . $model->PERF_LOCATION . 'L_TOTAL+'.$model->AMOUNT)],'USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH',[':USER_ID'=>$model->USER_ID,':CALC_MONTH'=>$lastMonth['yearMonth']]);
  441. $locaionField = 'PV_' . $model->PERF_LOCATION . 'L';
  442. $perfBefore = $perfModel->$locaionField;
  443. $perfAfter = $perfModel->$locaionField + $model->AMOUNT;
  444. $perfModel->$locaionField = $perfAfter;
  445. if (!$perfModel->save()) {
  446. throw new Exception(Form::formatErrorsForApi($perfModel->getErrors()));
  447. }
  448. } elseif ($model->PERF_TYPE == PerfAudit::PERF_TYPE_SURPLUS) {
  449. if($model->PERF_LOCATION==6){
  450. $locaionField = 'SURPLUS_LS';
  451. }else{
  452. $locaionField = 'SURPLUS_' . $model->PERF_LOCATION . 'L';
  453. }
  454. $perfBefore = $periodModel->$locaionField;
  455. $perfAfter = $periodModel->$locaionField + $model->AMOUNT;
  456. $periodModel->$locaionField = $perfAfter;
  457. if (!$periodModel->save()) {
  458. throw new Exception(Form::formatErrorsForApi($periodModel->getErrors()));
  459. }
  460. }
  461. }
  462. $model->PV_1L = $perfModel->PV_1L;
  463. $model->PV_2L = $perfModel->PV_2L;
  464. $model->PV_3L = $perfModel->PV_3L;
  465. $model->PV_4L = $perfModel->PV_4L;
  466. $model->PV_5L = $perfModel->PV_5L;
  467. $model->SURPLUS_1L = $periodModel->SURPLUS_1L;
  468. $model->SURPLUS_2L = $periodModel->SURPLUS_2L;
  469. $model->SURPLUS_3L = $periodModel->SURPLUS_3L;
  470. $model->SURPLUS_4L = $periodModel->SURPLUS_4L;
  471. $model->SURPLUS_5L = $periodModel->SURPLUS_5L;
  472. $model->SURPLUS_LS = $periodModel->SURPLUS_LS;
  473. $model->PERF_BEFORE = $perfBefore;
  474. $model->PERF_AFTER = $perfAfter;
  475. if (!$model->save()) {
  476. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  477. }
  478. $logs[] = ['userId' => $select];
  479. }
  480. if($this->auditStatus=='true'){
  481. $this->adminOperateLogger->fetchClass = UserPerf::class;
  482. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($uids, 'USER_ID');
  483. $perfData = $this->adminOperateLogger->saveAfterContent;
  484. $this->adminOperateLogger->fetchClass = PerfPeriod::class;
  485. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($uids, 'USER_ID');
  486. $periodData = $this->adminOperateLogger->saveAfterContent;
  487. $this->adminOperateLogger->saveAfterContent=Tool::mergeArrayWithKey($perfData,$periodData);
  488. $this->adminOperateLogger->setBatchField('USER_ID')->setOptObjField('USER_ID')->clean()->save([
  489. 'optType' => '审核会员业绩',
  490. 'remark' => $this->remark,
  491. ]);
  492. }else{
  493. $this->adminOperateLogger->fetchClass = PerfAudit::class;
  494. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->selected, 'ID')->clean()->save([
  495. 'optType' => '审核会员业绩',
  496. 'remark' => $this->remark,
  497. ]);
  498. }
  499. $transaction->commit();
  500. } catch (Exception $e) {
  501. $transaction->rollBack();
  502. $this->addError('changeAudit', $e->getMessage());
  503. return null;
  504. }
  505. return $logs;
  506. }
  507. /**
  508. * 删除前
  509. * @param $selected
  510. */
  511. public function beforeDelete($selected) {
  512. $this->adminOperateLogger->fetchClass = PerfAudit::class;
  513. $this->adminOperateLogger->setIsBatch(true)->beforeDelete($selected, 'ID');
  514. }
  515. /**
  516. * 删除
  517. * @param $selected
  518. * @throws Exception
  519. */
  520. public function delete($selected) {
  521. $this->adminOperateLogger->clean()->save([
  522. 'optType' => '删除业绩调整待审核数据',
  523. ]);
  524. }
  525. }