ChangePerfForm.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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, \Yii::t('ctx', 'applicationCannotReviewedAgain'));// 该申请已经被审核,不能重复审核
  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, \Yii::t('ctx', 'pendingRecordAfterThePendingReviewed')); // 该会员审核列表中如果有待审记录,需等待待审核记录审核后才可提交
  110. }
  111. } else {
  112. $this->addError($attribute, \Yii::t('ctx', 'memberDoesNotExist')); // 会员不存在
  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. $this->addError($attribute, \Yii::t('ctx', 'periodNotNetCannotAdjusted', ['periodNum' => $this->periodNum]));
  124. }
  125. 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) {
  126. $this->addError($attribute, \Yii::t('ctx', 'nextPeriodConnectedNetCannotAdjusted', ['periodNum' => $this->periodNum+1]));
  127. // $this->addError($attribute, '下一期【' . ($this->periodNum + 1) . '】已挂网,该期无法调整');
  128. }
  129. }
  130. /**
  131. * 类型是否符合条件
  132. * @param $attribute
  133. */
  134. public function isPerfType($attribute) {
  135. if (!in_array($this->perfType, array_keys(PerfAudit::CHANGE_PERF_TYPE))) {
  136. $this->addError($attribute, \Yii::t('ctx', 'adjustmentTypeIncorrect')); // 调整类型不正确
  137. }
  138. $this->_periodNum = Period::sentMaxPeriodNum();
  139. }
  140. /**
  141. * 校验区域
  142. * @param $attribute
  143. */
  144. public function isLocation($attribute) {
  145. if ($this->perfType==PerfAudit::PERF_TYPE_PV && !in_array($this->location, [1, 2, 3, 4, 5])) {
  146. $this->addError($attribute, \Yii::t('ctx', 'incorrectLocation')); // 区位不正确
  147. }
  148. if ($this->perfType==PerfAudit::PERF_TYPE_SURPLUS && !in_array($this->location, [1, 2, 3, 4, 5, 6])) {
  149. $this->addError($attribute, \Yii::t('ctx', 'incorrectLocation')); // 区位不正确
  150. }
  151. }
  152. /**
  153. * 金额是否正确
  154. * @param $attribute
  155. */
  156. public function isAmount($attribute) {
  157. if ($this->amount == 0) $this->addError($attribute, \Yii::t('ctx', 'amountChangeCannotZero')); // 变动数额不能为0
  158. if ($this->perfType == PerfAudit::PERF_TYPE_PV) {
  159. $userPerf = UserPerf::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $this->_userId]);
  160. if ($this->amount < 0 && (abs($this->amount) > $userPerf['PV_' . $this->location . 'L'])) {
  161. $this->addError('scenario', \Yii::t('ctx', 'memberUnderrepresentedRegion')); // 该会员该区域的数额不足
  162. }
  163. } elseif ($this->perfType == PerfAudit::PERF_TYPE_SURPLUS) {
  164. $perfPeriod = PerfPeriod::findOneAsArray('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [':USER_ID' => $this->_userId, ':PERIOD_NUM' => $this->_periodNum]);
  165. if($this->location==6){
  166. if ($this->amount < 0 && (abs($this->amount) > $perfPeriod['SURPLUS_LS'])) {
  167. $this->addError('scenario', \Yii::t('ctx', 'memberSurplusRegionLess')); // 该会员当期该区域剩余数额不足
  168. }
  169. }else {
  170. if ($this->amount < 0 && (abs($this->amount) > $perfPeriod['SURPLUS_' . $this->location . 'L'])) {
  171. $this->addError('scenario', \Yii::t('ctx', 'memberSurplusRegionLess')); // 该会员当期该区域剩余数额不足
  172. }
  173. }
  174. }
  175. }
  176. /**
  177. * 校验状态
  178. * @param $attribute
  179. */
  180. public function isStatus($attribute) {
  181. // 获取当前提现单的状态
  182. $oneData = PerfAudit::findOneAsArray(['ID' => $this->id]);
  183. switch ($this->auditStatus) {
  184. case 'un':
  185. $this->addError($attribute, \Yii::t('ctx', 'cannotSetPendingReview') . $this->auditStatus); // 不能设置为待审核状态
  186. break;
  187. case 'true':
  188. if ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['true']['value']) {
  189. $this->addError($attribute, \Yii::t('ctx', 'auditCannotRepeated')); // 已经审核通过不能重复审核
  190. } elseif ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['reject']['value']) {
  191. $this->addError($attribute, \Yii::t('ctx', 'rejectedAuditCannotRepeated')); // 已经审核拒绝不能重复审核
  192. }
  193. break;
  194. case 'reject':
  195. if ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['true']['value']) {
  196. $this->addError($attribute, \Yii::t('ctx', 'auditCannotRepeated')); // 已经审核通过不能重复审核
  197. } elseif ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['reject']['value']) {
  198. $this->addError($attribute, \Yii::t('ctx', 'rejectedAuditCannotRepeated')); // 已经审核拒绝不能重复审核
  199. }
  200. break;
  201. default:
  202. $this->addError($attribute, \Yii::t('ctx', 'statusParameterError'));
  203. }
  204. }
  205. /**
  206. * 批量数据
  207. * @param $attributes
  208. */
  209. public function isSelected($attributes) {
  210. if (!$this->selected) {
  211. $this->addError($attributes, \Yii::t('ctx', 'aPieceMustBeSelected')); // 必须选择一条数据
  212. }
  213. if (!is_array($this->selected)) {
  214. $this->selected = [$this->selected];
  215. }
  216. }
  217. /**
  218. * 添加变动申请
  219. * @return BalanceAudit|null
  220. * @throws \yii\db\Exception
  221. */
  222. public function add() {
  223. if (!$this->validate()) {
  224. return null;
  225. }
  226. $db = \Yii::$app->db;
  227. $transaction = $db->beginTransaction();
  228. try {
  229. // 添加申请
  230. $model = new PerfAudit();
  231. $model->USER_ID = $this->_userId;
  232. $model->PERF_TYPE = $this->perfType;
  233. $model->PERF_LOCATION = $this->location;
  234. $model->PERIOD_NUM = $this->_periodNum;
  235. $model->AMOUNT = $this->amount;
  236. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['un']['value'];
  237. $model->CREATE_ADMIN = \Yii::$app->user->id;
  238. $model->REMARK = $this->remark;
  239. $model->CREATED_AT = Date::nowTime();
  240. if (!$model->save()) {
  241. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  242. }
  243. $transaction->commit();
  244. } catch (Exception $e) {
  245. $transaction->rollBack();
  246. $this->addError('add', $e->getMessage());
  247. return null;
  248. }
  249. // 记录日志
  250. $this->adminOperateLogger->fetchClass = PerfAudit::class;
  251. $this->adminOperateLogger->afterInsert($model)->clean()->save([
  252. 'optType' => '申请调整会员业绩',
  253. 'userId' => $model->USER_ID,
  254. 'userName' => Info::getUserNameByUserId($model->USER_ID),
  255. 'remark' => $model->REMARK,
  256. ]);
  257. return $model;
  258. }
  259. /**
  260. * 管理员审核状态
  261. * @return BalanceAudit|null
  262. * @throws \yii\db\Exception
  263. */
  264. /*public function changeStatus() {
  265. if (!$this->validate()) {
  266. return null;
  267. }
  268. $db = \Yii::$app->db;
  269. $transaction = $db->beginTransaction();
  270. try {
  271. $model = $this->_model;
  272. if ($this->auditStatus == 'reject') {
  273. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['reject']['value'];
  274. } elseif ($this->auditStatus == 'true') {
  275. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['true']['value'];
  276. }
  277. $model->AUDIT_ADMIN = \Yii::$app->user->id;
  278. $model->AUDITED_AT = Date::nowTime();
  279. if (!$model->save()) {
  280. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  281. }
  282. // 如果是审核通过状态改变会员的业绩
  283. if ($this->auditStatus == 'true') {
  284. UserPerf::updateAllCounters([$this->_locationField => $this->amount], 'USER_ID=:USER_ID', [':USER_ID' => $model['USER_ID']]);
  285. }
  286. $transaction->commit();
  287. } catch (Exception $e) {
  288. $transaction->rollBack();
  289. $this->addError('status', $e->getMessage());
  290. return null;
  291. }
  292. return $model;
  293. }*/
  294. /**
  295. * 审核通过
  296. * @return null
  297. * @throws \yii\db\Exception
  298. */
  299. public function pass() {
  300. if (!$this->validate()) {
  301. return null;
  302. }
  303. // 日志记录操作前的数据
  304. $beforeData = UserPerf::getPvByUserId($this->_userId);
  305. $this->adminOperateLogger->fetchClass = UserPerf::class;
  306. $this->adminOperateLogger->beforeUpdate($beforeData);
  307. $perfData = $this->adminOperateLogger->saveBeforeContent;
  308. $beforeData = PerfPeriod::getPeriodSurplusPerf($this->_model->PERIOD_NUM,$this->_userId);
  309. $this->adminOperateLogger->fetchClass = PerfPeriod::class;
  310. $this->adminOperateLogger->beforeUpdate($beforeData);
  311. $periodData = $this->adminOperateLogger->saveBeforeContent;
  312. $this->adminOperateLogger->saveBeforeContent=array_merge($perfData,$periodData);
  313. $db = \Yii::$app->db;
  314. $transaction = $db->beginTransaction();
  315. try {
  316. $model = $this->_model;
  317. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus'][$this->auditStatus]['value'];
  318. $model->AUDIT_ADMIN = \Yii::$app->user->id;
  319. $model->AMOUNT = $this->amount;
  320. $model->REMARK = $this->remark;
  321. $model->AUDITED_AT = Date::nowTime();
  322. $perfModel = UserPerf::findOne(['USER_ID' => $model->USER_ID]);
  323. $periodModel = PerfPeriod::findOne(['USER_ID' => $model->USER_ID, 'PERIOD_NUM' => $model->PERIOD_NUM]);
  324. $perfBefore = 0;
  325. $perfAfter = 0;
  326. // 如果是审核通过状态
  327. if ($this->auditStatus == 'true') {
  328. if ($model->PERF_TYPE == PerfAudit::PERF_TYPE_PV) {
  329. //给上月累计
  330. $period = Period::instance();
  331. $lastMonth = $period->getLastMonth();
  332. 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']]);
  333. $locaionField = 'PV_' . $model->PERF_LOCATION . 'L';
  334. $perfBefore = $perfModel->$locaionField;
  335. $perfAfter = $perfModel->$locaionField + $model->AMOUNT;
  336. $perfModel->$locaionField = $perfAfter;
  337. if (!$perfModel->save()) {
  338. throw new Exception(Form::formatErrorsForApi($perfModel->getErrors()));
  339. }
  340. } elseif ($model->PERF_TYPE == PerfAudit::PERF_TYPE_SURPLUS) {
  341. if($model->PERF_LOCATION==6){
  342. $locaionField = 'SURPLUS_LS';
  343. }else{
  344. $locaionField = 'SURPLUS_' . $model->PERF_LOCATION . 'L';
  345. }
  346. $perfBefore = $periodModel->$locaionField;
  347. $perfAfter = $periodModel->$locaionField + $model->AMOUNT;
  348. $periodModel->$locaionField = $perfAfter;
  349. if (!$periodModel->save()) {
  350. throw new Exception(Form::formatErrorsForApi($periodModel->getErrors()));
  351. }
  352. }
  353. }
  354. $model->PV_1L = $perfModel->PV_1L;
  355. $model->PV_2L = $perfModel->PV_2L;
  356. $model->PV_3L = $perfModel->PV_3L;
  357. $model->PV_4L = $perfModel->PV_4L;
  358. $model->PV_5L = $perfModel->PV_5L;
  359. $model->SURPLUS_1L = $periodModel->SURPLUS_1L;
  360. $model->SURPLUS_2L = $periodModel->SURPLUS_2L;
  361. $model->SURPLUS_3L = $periodModel->SURPLUS_3L;
  362. $model->SURPLUS_4L = $periodModel->SURPLUS_4L;
  363. $model->SURPLUS_5L = $periodModel->SURPLUS_5L;
  364. $model->SURPLUS_LS = $periodModel->SURPLUS_LS;
  365. $model->PERF_BEFORE = $perfBefore;
  366. $model->PERF_AFTER = $perfAfter;
  367. if (!$model->save()) {
  368. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  369. }
  370. $transaction->commit();
  371. } catch (Exception $e) {
  372. $transaction->rollBack();
  373. $this->addError('pass', $e->getMessage());
  374. return null;
  375. }
  376. // 记录日志
  377. $beforeData = UserPerf::getPvByUserId($this->_userId);
  378. $this->adminOperateLogger->fetchClass = UserPerf::class;
  379. $this->adminOperateLogger->afterUpdate($beforeData);
  380. $perfData = $this->adminOperateLogger->saveAfterContent;
  381. $beforeData = PerfPeriod::getPeriodSurplusPerf($this->_model->PERIOD_NUM,$this->_userId);
  382. $this->adminOperateLogger->fetchClass = PerfPeriod::class;
  383. $this->adminOperateLogger->afterUpdate($beforeData);
  384. $periodData = $this->adminOperateLogger->saveAfterContent;
  385. $this->adminOperateLogger->saveAfterContent=array_merge($perfData,$periodData);
  386. $this->adminOperateLogger->clean()->save([
  387. 'optType' => 'Review and approve the performance of members', // 审核通过会员业绩
  388. 'userId' => $model->USER_ID,
  389. 'userName' => Info::getUserNameByUserId($model->USER_ID),
  390. 'remark' => $model->REMARK,
  391. ]);
  392. return $model;
  393. }
  394. /**
  395. * 修改审核状态
  396. * @return array|null
  397. * @throws \yii\db\Exception
  398. */
  399. public function changeAudit() {
  400. if (!$this->validate()) {
  401. return null;
  402. }
  403. $db = \Yii::$app->db;
  404. $transaction = $db->beginTransaction();
  405. $logs = [];
  406. $uids=[];
  407. if($this->auditStatus=='true'){
  408. foreach ($this->selected as $select) {
  409. $oneBalanceAudit = PerfAudit::findOneAsArray('ID=:ID',[':ID'=>$select],'USER_ID');
  410. $uids[]=$oneBalanceAudit['USER_ID'];
  411. }
  412. }
  413. try {
  414. if($this->auditStatus=='true'){
  415. $this->adminOperateLogger->fetchClass = UserPerf::class;
  416. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($uids, 'USER_ID');
  417. $perfData = $this->adminOperateLogger->saveBeforeContent;
  418. $this->adminOperateLogger->fetchClass = PerfPeriod::class;
  419. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($uids, 'USER_ID');
  420. $periodData = $this->adminOperateLogger->saveBeforeContent;
  421. $this->adminOperateLogger->saveBeforeContent=Tool::mergeArrayWithKey($perfData,$periodData);
  422. }else{
  423. $this->adminOperateLogger->fetchClass = PerfAudit::class;
  424. $this->adminOperateLogger->setIsBatch(true)->beforeUpdate($this->selected, 'ID');
  425. }
  426. foreach ($this->selected as $select) {
  427. $model = PerfAudit::findOne(['ID' => $select]);
  428. if ($model->AUDIT_STATUS > \Yii::$app->params['auditStatus']['un']['value']) continue;
  429. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus'][$this->auditStatus]['value'];
  430. $model->AUDIT_ADMIN = \Yii::$app->user->id;
  431. $model->REMARK = $this->remark;
  432. $model->AUDITED_AT = Date::nowTime();
  433. $perfModel = UserPerf::findOne(['USER_ID' => $model->USER_ID]);
  434. $periodModel = PerfPeriod::findOne(['USER_ID' => $model->USER_ID, 'PERIOD_NUM' => $model->PERIOD_NUM]);
  435. $perfBefore = 0;
  436. $perfAfter = 0;
  437. if ($model->AUDIT_STATUS == \Yii::$app->params['auditStatus']['true']['value']) {
  438. if ($model->PERF_TYPE == PerfAudit::PERF_TYPE_PV) {
  439. //给上月累计
  440. $period = Period::instance();
  441. $lastMonth = $period->getLastMonth();
  442. 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']]);
  443. $locaionField = 'PV_' . $model->PERF_LOCATION . 'L';
  444. $perfBefore = $perfModel->$locaionField;
  445. $perfAfter = $perfModel->$locaionField + $model->AMOUNT;
  446. $perfModel->$locaionField = $perfAfter;
  447. if (!$perfModel->save()) {
  448. throw new Exception(Form::formatErrorsForApi($perfModel->getErrors()));
  449. }
  450. } elseif ($model->PERF_TYPE == PerfAudit::PERF_TYPE_SURPLUS) {
  451. if($model->PERF_LOCATION==6){
  452. $locaionField = 'SURPLUS_LS';
  453. }else{
  454. $locaionField = 'SURPLUS_' . $model->PERF_LOCATION . 'L';
  455. }
  456. $perfBefore = $periodModel->$locaionField;
  457. $perfAfter = $periodModel->$locaionField + $model->AMOUNT;
  458. $periodModel->$locaionField = $perfAfter;
  459. if (!$periodModel->save()) {
  460. throw new Exception(Form::formatErrorsForApi($periodModel->getErrors()));
  461. }
  462. }
  463. }
  464. $model->PV_1L = $perfModel->PV_1L;
  465. $model->PV_2L = $perfModel->PV_2L;
  466. $model->PV_3L = $perfModel->PV_3L;
  467. $model->PV_4L = $perfModel->PV_4L;
  468. $model->PV_5L = $perfModel->PV_5L;
  469. $model->SURPLUS_1L = $periodModel->SURPLUS_1L;
  470. $model->SURPLUS_2L = $periodModel->SURPLUS_2L;
  471. $model->SURPLUS_3L = $periodModel->SURPLUS_3L;
  472. $model->SURPLUS_4L = $periodModel->SURPLUS_4L;
  473. $model->SURPLUS_5L = $periodModel->SURPLUS_5L;
  474. $model->SURPLUS_LS = $periodModel->SURPLUS_LS;
  475. $model->PERF_BEFORE = $perfBefore;
  476. $model->PERF_AFTER = $perfAfter;
  477. if (!$model->save()) {
  478. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  479. }
  480. $logs[] = ['userId' => $select];
  481. }
  482. if($this->auditStatus=='true'){
  483. $this->adminOperateLogger->fetchClass = UserPerf::class;
  484. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($uids, 'USER_ID');
  485. $perfData = $this->adminOperateLogger->saveAfterContent;
  486. $this->adminOperateLogger->fetchClass = PerfPeriod::class;
  487. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($uids, 'USER_ID');
  488. $periodData = $this->adminOperateLogger->saveAfterContent;
  489. $this->adminOperateLogger->saveAfterContent=Tool::mergeArrayWithKey($perfData,$periodData);
  490. $this->adminOperateLogger->setBatchField('USER_ID')->setOptObjField('USER_ID')->clean()->save([
  491. 'optType' => 'Review member performance', // 审核会员业绩
  492. 'remark' => $this->remark,
  493. ]);
  494. }else{
  495. $this->adminOperateLogger->fetchClass = PerfAudit::class;
  496. $this->adminOperateLogger->setIsBatch(true)->afterUpdate($this->selected, 'ID')->clean()->save([
  497. 'optType' => 'Review member performance', // 审核会员业绩
  498. 'remark' => $this->remark,
  499. ]);
  500. }
  501. $transaction->commit();
  502. } catch (Exception $e) {
  503. $transaction->rollBack();
  504. $this->addError('changeAudit', $e->getMessage());
  505. return null;
  506. }
  507. return $logs;
  508. }
  509. /**
  510. * 删除前
  511. * @param $selected
  512. */
  513. public function beforeDelete($selected) {
  514. $this->adminOperateLogger->fetchClass = PerfAudit::class;
  515. $this->adminOperateLogger->setIsBatch(true)->beforeDelete($selected, 'ID');
  516. }
  517. /**
  518. * 删除
  519. * @param $selected
  520. * @throws Exception
  521. */
  522. public function delete($selected) {
  523. $this->adminOperateLogger->clean()->save([
  524. 'optType' => 'Delete performance adjustment pending review data', // 删除业绩调整待审核数据
  525. ]);
  526. }
  527. }