RegInfoAuditForm.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <?php
  2. namespace common\models\forms;
  3. use common\helpers\Date;
  4. use common\helpers\user\Info;
  5. use common\helpers\user\Status;
  6. use common\components\Model;
  7. use common\helpers\Form;
  8. use common\models\CompanyBank;
  9. use common\models\Period;
  10. use common\models\RegInfoAudit;
  11. use common\models\RegType;
  12. use common\models\User;
  13. use common\models\UserInfo;
  14. use yii\base\Exception;
  15. /**
  16. * 注册信息表单
  17. */
  18. class RegInfoAuditForm extends Model {
  19. public $id;
  20. public $userId;
  21. public $userName;
  22. public $realName;
  23. public $idCard;
  24. public $type;
  25. public $regName;
  26. public $creditCode;
  27. public $premises;
  28. public $legalPerson;
  29. public $regExpires;
  30. public $createRemark;
  31. public $auditRemark;
  32. public $auditStatus;
  33. public $companyBank;
  34. public $openName;
  35. public $openBank;
  36. public $bankAddress;
  37. public $bankNo;
  38. public $bankAreaSelected;
  39. private $_uid;
  40. private $_model;
  41. /**
  42. * @inheritdoc
  43. */
  44. public function rules() {
  45. return [
  46. [['id', 'userId', 'userName', 'realName', 'idCard', 'type', 'regName', 'creditCode', 'premises', 'legalPerson', 'regExpires', 'createRemark', 'auditRemark', 'auditStatus', 'companyBank', 'openName', 'openBank', 'bankAddress', 'bankNo', 'bankAreaSelected'], 'trim'],
  47. [['id', 'userName', 'realName', 'idCard', 'type', 'regName', 'creditCode', 'auditStatus'], 'required'],
  48. [['userName'], 'isUserName'],
  49. [['id'], 'initModel'],
  50. [['auditStatus'], 'isAuditStatus'],
  51. [['type'], 'isType'],
  52. ];
  53. }
  54. /**
  55. * 指定校验场景
  56. * @return array
  57. */
  58. public function scenarios() {
  59. $parentScenarios = parent::scenarios();
  60. $customScenarios = [
  61. 'add' => ['userName', 'realName', 'idCard', 'type', 'regName', 'creditCode', 'premises', 'legalPerson', 'regExpires', 'createRemark', 'companyBank'],
  62. 'excelAdd' => ['userName', 'realName', 'idCard', 'type', 'regName', 'creditCode', 'premises', 'legalPerson', 'regExpires', 'createRemark', 'openName', 'openBank', 'bankAddress', 'bankNo', 'bankAreaSelected'],
  63. 'editRegInfo' => ['userId', 'type', 'regName', 'creditCode', 'premises', 'legalPerson', 'regExpires', 'createRemark', 'companyBank'],
  64. 'edit' => ['id', 'type', 'regName', 'creditCode', 'premises', 'legalPerson', 'regExpires', 'createRemark', 'companyBank'],
  65. 'audit' => ['id', 'type', 'regName', 'creditCode', 'premises', 'legalPerson', 'regExpires', 'createRemark', 'auditStatus', 'companyBank'],
  66. ];
  67. return array_merge($parentScenarios, $customScenarios);
  68. }
  69. public function attributeLabels() {
  70. return [
  71. 'userId' => '会员ID',
  72. 'userName' => '会员编号',
  73. 'realName' => '会员姓名',
  74. 'idCard' => '身份证号',
  75. 'type' => '注册类型',
  76. 'regName' => '注册名称',
  77. 'creditCode' => '统一社会信用代码',
  78. 'premises' => '经营场所',
  79. 'legalPerson' => '经营者/法人',
  80. 'regExpires' => '注册有效期',
  81. 'createRemark' => '创建备注',
  82. 'auditRemark' => '审核备注',
  83. 'auditStatus' => '审核状态',
  84. ];
  85. }
  86. /**
  87. * 初始化model
  88. * @param $attributes
  89. */
  90. public function initModel($attributes) {
  91. $this->_model = RegInfoAudit::findOne(['ID' => $this->id]);
  92. if (!$this->_model) {
  93. $this->addError($attributes, 'The data does not exist'); // 数据不存在
  94. }
  95. if ($this->_model->AUDIT_STATUS != \Yii::$app->params['auditStatus']['un']['value']) {
  96. $this->addError($attributes, '本数据已经被处理过了');
  97. }
  98. }
  99. /**
  100. * 用户名是否正确
  101. * @param $attributes
  102. */
  103. public function isUserName($attributes) {
  104. $userInfo = UserInfo::findOneAsArray(['USER_NAME' => $this->userName]);
  105. if ($userInfo) {
  106. $baseInfo = Info::baseInfoZh($userInfo['USER_ID']);
  107. if ($baseInfo['REAL_NAME'] != $this->realName || $baseInfo['ID_CARD'] != $this->idCard) {
  108. $this->addError($attributes, '输入的会员姓名或身份证号与系统不一致');
  109. }
  110. if (RegInfoAudit::find()->where('USER_ID=:USER_ID AND AUDIT_STATUS=0', [':USER_ID' => $userInfo['USER_ID']])->exists()) {
  111. $this->addError($attributes, '填写的会员有待审核的注册信息');
  112. }
  113. $this->_uid = $userInfo['USER_ID'];
  114. } else {
  115. $this->addError($attributes, 'Member does not exist'); // 会员不存在
  116. }
  117. }
  118. /**
  119. * 注册类型检测
  120. * @param $attributes
  121. */
  122. public function isType($attributes) {
  123. $type = RegType::findOneAsArray('ID=:ID', [':ID' => $this->type], 'ID');
  124. if ($type) {
  125. //暂写死
  126. if ($type['ID'] == '758BF69C25C3422AA7743936BC77EE64') {
  127. if($this->scenario=='excelAdd'){
  128. if ($this->openName == '' || $this->openBank == '' || $this->bankAddress == '' || $this->bankNo == '' || $this->bankAreaSelected == []) {
  129. $this->addError($attributes, '请完善公司银行信息');
  130. }
  131. }else {
  132. if ($this->companyBank['openBank'] == '' || $this->companyBank['bankAreaSelected'] == [] || $this->companyBank['bankAddress'] == '' || $this->companyBank['openName'] == '' || $this->companyBank['bankNo'] == '') {
  133. $this->addError($attributes, '请完善公司银行信息');
  134. }
  135. }
  136. }
  137. } else {
  138. $this->addError($attributes, '错误的注册类型');
  139. }
  140. }
  141. /**
  142. * 审核状态是否正确
  143. * @param $attributes
  144. */
  145. public function isAuditStatus($attributes) {
  146. if (!array_key_exists($this->auditStatus, \Yii::$app->params['auditStatus'])) {
  147. $this->addError($attributes, '无效的审核状态');
  148. }
  149. }
  150. /**
  151. * 添加
  152. * @return RegInfoAudit|null
  153. * @throws \yii\db\Exception
  154. */
  155. public function add() {
  156. if (!$this->validate()) {
  157. return null;
  158. }
  159. $transaction = \Yii::$app->db->beginTransaction();
  160. try {
  161. $period = Period::instance();
  162. // 添加会员注册信息
  163. $model = new RegInfoAudit();
  164. $model->USER_ID = $this->_uid;
  165. $model->REG_TYPE = $this->type;
  166. $model->REG_NAME = $this->regName;
  167. $model->CREDIT_CODE = $this->creditCode;
  168. $model->PREMISES = $this->premises;
  169. $model->LEGAL_PERSON = $this->legalPerson;
  170. $model->REG_EXPIRES = $this->regExpires ? Date::utcToTime($this->regExpires) : 0;
  171. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['un']['value'];
  172. $model->CREATE_ADMIN = \Yii::$app->user->id;
  173. $model->CREATE_REMARK = $this->createRemark;
  174. $model->CREATE_PERIOD = $period->getNowPeriodNum();
  175. $model->CREATED_AT = Date::nowTime();
  176. if (!$model->save()) {
  177. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  178. }
  179. //暂写死
  180. if ($this->type == '758BF69C25C3422AA7743936BC77EE64') {
  181. if (!CompanyBank::find()->where('USER_ID=:USER_ID', [':USER_ID' => $this->_uid])->exists()) {
  182. $companyBank = new CompanyBank();
  183. $companyBank->USER_ID = $this->_uid;
  184. $companyBank->CREATE_ADMIN = \Yii::$app->user->id;
  185. $companyBank->CREATED_AT = Date::nowTime();
  186. } else {
  187. $companyBank = CompanyBank::findOne(['USER_ID' => $this->_uid]);
  188. $companyBank->UPDATE_ADMIN = \Yii::$app->user->id;
  189. $companyBank->UPDATED_AT = Date::nowTime();
  190. }
  191. $companyBank->OPEN_NAME = $this->companyBank['openName'];
  192. $companyBank->OPEN_BANK = $this->companyBank['openBank'];
  193. $companyBank->BANK_ADDRESS = $this->companyBank['bankAddress'];
  194. $companyBank->BANK_NO = $this->companyBank['bankNo'];
  195. $companyBank->BANK_PROVINCE = $this->companyBank['bankAreaSelected'][0] ?? '0';
  196. $companyBank->BANK_CITY = $this->companyBank['bankAreaSelected'][1] ?? '0';
  197. $companyBank->BANK_COUNTY = $this->companyBank['bankAreaSelected'][2] ?? '0';
  198. $companyBank->REMARK = $this->createRemark;
  199. if (!$companyBank->save()) {
  200. throw new Exception(Form::formatErrorsForApi($companyBank->getErrors()));
  201. }
  202. }
  203. $transaction->commit();
  204. } catch (Exception $e) {
  205. $transaction->rollBack();
  206. $this->addError('add', $e->getMessage());
  207. return null;
  208. }
  209. return $model;
  210. }
  211. /**
  212. * 批量导入注册信息
  213. * @return RegInfoAudit|null
  214. * @throws \yii\db\Exception
  215. */
  216. public function excelAdd() {
  217. if (!$this->validate()) {
  218. return null;
  219. }
  220. $transaction = \Yii::$app->db->beginTransaction();
  221. try {
  222. $period = Period::instance();
  223. // 添加会员注册信息
  224. $model = new RegInfoAudit();
  225. $model->USER_ID = $this->_uid;
  226. $model->REG_TYPE = $this->type;
  227. $model->REG_NAME = $this->regName;
  228. $model->CREDIT_CODE = $this->creditCode;
  229. $model->PREMISES = $this->premises;
  230. $model->LEGAL_PERSON = $this->legalPerson;
  231. $model->REG_EXPIRES = $this->regExpires ? Date::utcToTime($this->regExpires) : 0;
  232. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['un']['value'];
  233. $model->CREATE_ADMIN = \Yii::$app->user->id;
  234. $model->CREATE_REMARK = $this->createRemark;
  235. $model->CREATE_PERIOD = $period->getNowPeriodNum();
  236. $model->CREATED_AT = Date::nowTime();
  237. if (!$model->save()) {
  238. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  239. }
  240. //暂写死
  241. if ($this->type == '758BF69C25C3422AA7743936BC77EE64') {
  242. if (!CompanyBank::find()->where('USER_ID=:USER_ID', [':USER_ID' => $this->_uid])->exists()) {
  243. $companyBank = new CompanyBank();
  244. $companyBank->USER_ID = $this->_uid;
  245. $companyBank->CREATE_ADMIN = \Yii::$app->user->id;
  246. $companyBank->CREATED_AT = Date::nowTime();
  247. } else {
  248. $companyBank = CompanyBank::findOne(['USER_ID' => $this->_uid]);
  249. $companyBank->UPDATE_ADMIN = \Yii::$app->user->id;
  250. $companyBank->UPDATED_AT = Date::nowTime();
  251. }
  252. $companyBank->OPEN_NAME = $this->openName;
  253. $companyBank->OPEN_BANK = $this->openBank;
  254. $companyBank->BANK_ADDRESS = $this->bankAddress;
  255. $companyBank->BANK_NO = $this->bankNo;
  256. $companyBank->BANK_PROVINCE = $this->bankAreaSelected[0] ?? '0';
  257. $companyBank->BANK_CITY = $this->bankAreaSelected[1] ?? '0';
  258. $companyBank->BANK_COUNTY = $this->bankAreaSelected[2] ?? '0';
  259. $companyBank->REMARK = $this->createRemark;
  260. if (!$companyBank->save()) {
  261. throw new Exception(Form::formatErrorsForApi($companyBank->getErrors()));
  262. }
  263. }
  264. $transaction->commit();
  265. } catch (Exception $e) {
  266. $transaction->rollBack();
  267. $this->addError('excelAdd', $e->getMessage());
  268. return null;
  269. }
  270. return $model;
  271. }
  272. /**
  273. * 注册信息管理中提交修改注册信息
  274. * @return RegInfoAudit|null
  275. * @throws \yii\db\Exception
  276. */
  277. public function editRegInfo() {
  278. if (!$this->validate()) {
  279. return null;
  280. }
  281. $transaction = \Yii::$app->db->beginTransaction();
  282. try {
  283. $period = Period::instance();
  284. // 添加会员注册信息
  285. $model = new RegInfoAudit();
  286. $model->USER_ID = $this->userId;
  287. $model->REG_TYPE = $this->type;
  288. $model->REG_NAME = $this->regName;
  289. $model->CREDIT_CODE = $this->creditCode;
  290. $model->PREMISES = $this->premises;
  291. $model->LEGAL_PERSON = $this->legalPerson;
  292. $model->REG_EXPIRES = $this->regExpires ? Date::utcToTime($this->regExpires) : 0;
  293. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['un']['value'];
  294. $model->CREATE_ADMIN = \Yii::$app->user->id;
  295. $model->CREATE_REMARK = $this->createRemark;
  296. $model->CREATE_PERIOD = $period->getNowPeriodNum();
  297. $model->CREATED_AT = Date::nowTime();
  298. if (!$model->save()) {
  299. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  300. }
  301. //暂写死
  302. if ($this->type == '758BF69C25C3422AA7743936BC77EE64') {
  303. if (!CompanyBank::find()->where('USER_ID=:USER_ID', [':USER_ID' => $this->userId])->exists()) {
  304. $companyBank = new CompanyBank();
  305. $companyBank->USER_ID = $this->userId;
  306. $companyBank->CREATE_ADMIN = \Yii::$app->user->id;
  307. $companyBank->CREATED_AT = Date::nowTime();
  308. } else {
  309. $companyBank = CompanyBank::findOne(['USER_ID' => $this->userId]);
  310. $companyBank->UPDATE_ADMIN = \Yii::$app->user->id;
  311. $companyBank->UPDATED_AT = Date::nowTime();
  312. }
  313. $companyBank->OPEN_NAME = $this->companyBank['openName'];
  314. $companyBank->OPEN_BANK = $this->companyBank['openBank'];
  315. $companyBank->BANK_ADDRESS = $this->companyBank['bankAddress'];
  316. $companyBank->BANK_NO = $this->companyBank['bankNo'];
  317. $companyBank->BANK_PROVINCE = $this->companyBank['bankAreaSelected'][0] ?? '0';
  318. $companyBank->BANK_CITY = $this->companyBank['bankAreaSelected'][1] ?? '0';
  319. $companyBank->BANK_COUNTY = $this->companyBank['bankAreaSelected'][2] ?? '0';
  320. $companyBank->REMARK = $this->createRemark;
  321. if (!$companyBank->save()) {
  322. throw new Exception(Form::formatErrorsForApi($companyBank->getErrors()));
  323. }
  324. }
  325. $transaction->commit();
  326. } catch (Exception $e) {
  327. $transaction->rollBack();
  328. $this->addError('add', $e->getMessage());
  329. return null;
  330. }
  331. return $model;
  332. }
  333. /**
  334. * 修改操作
  335. * @return null
  336. * @throws \yii\db\Exception
  337. */
  338. public function edit() {
  339. if (!$this->validate()) {
  340. return null;
  341. }
  342. $transaction = \Yii::$app->db->beginTransaction();
  343. try {
  344. $model = $this->_model;
  345. $model->REG_TYPE = $this->type;
  346. $model->REG_NAME = $this->regName;
  347. $model->CREDIT_CODE = $this->creditCode;
  348. $model->PREMISES = $this->premises;
  349. $model->LEGAL_PERSON = $this->legalPerson;
  350. $model->REG_EXPIRES = $this->regExpires ? Date::utcToTime($this->regExpires) : 0;
  351. if (!$model->save()) {
  352. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  353. }
  354. //暂写死
  355. if ($this->type == '758BF69C25C3422AA7743936BC77EE64') {
  356. if (!CompanyBank::find()->where('USER_ID=:USER_ID', [':USER_ID' => $model->USER_ID])->exists()) {
  357. $companyBank = new CompanyBank();
  358. $companyBank->USER_ID = $model->USER_ID;
  359. $companyBank->CREATE_ADMIN = \Yii::$app->user->id;
  360. $companyBank->CREATED_AT = Date::nowTime();
  361. } else {
  362. $companyBank = CompanyBank::findOne(['USER_ID' => $model->USER_ID]);
  363. $companyBank->UPDATE_ADMIN = \Yii::$app->user->id;
  364. $companyBank->UPDATED_AT = Date::nowTime();
  365. }
  366. $companyBank->OPEN_NAME = $this->companyBank['openName'];
  367. $companyBank->OPEN_BANK = $this->companyBank['openBank'];
  368. $companyBank->BANK_ADDRESS = $this->companyBank['bankAddress'];
  369. $companyBank->BANK_NO = $this->companyBank['bankNo'];
  370. $companyBank->BANK_PROVINCE = $this->companyBank['bankAreaSelected'][0] ?? '0';
  371. $companyBank->BANK_CITY = $this->companyBank['bankAreaSelected'][1] ?? '0';
  372. $companyBank->BANK_COUNTY = $this->companyBank['bankAreaSelected'][2] ?? '0';
  373. $companyBank->REMARK = $this->createRemark;
  374. if (!$companyBank->save()) {
  375. throw new Exception(Form::formatErrorsForApi($companyBank->getErrors()));
  376. }
  377. }
  378. $transaction->commit();
  379. } catch (Exception $e) {
  380. $transaction->rollBack();
  381. $this->addError('edit', $e->getMessage());
  382. return null;
  383. }
  384. return $model;
  385. }
  386. /**
  387. * 审核操作
  388. * @return null
  389. * @throws \yii\db\Exception
  390. */
  391. public function audit() {
  392. if (!$this->validate()) {
  393. return null;
  394. }
  395. $transaction = \Yii::$app->db->beginTransaction();
  396. try {
  397. $period = Period::instance();
  398. $model = $this->_model;
  399. if ($this->auditStatus == 'reject') {
  400. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['reject']['value'];
  401. } elseif ($this->auditStatus == 'true') {
  402. $model->AUDIT_STATUS = \Yii::$app->params['auditStatus']['true']['value'];
  403. $model->REG_TYPE = $this->type;
  404. $model->REG_NAME = $this->regName;
  405. $model->CREDIT_CODE = $this->creditCode;
  406. $model->PREMISES = $this->premises;
  407. $model->LEGAL_PERSON = $this->legalPerson;
  408. $model->REG_EXPIRES = $this->regExpires ? Date::utcToTime($this->regExpires) : 0;
  409. }
  410. $model->AUDIT_ADMIN = \Yii::$app->user->id;
  411. $model->CREATE_REMARK = $this->createRemark;
  412. $model->AUDIT_PERIOD = $period->getNowPeriodNum();
  413. $model->AUDITED_AT = Date::nowTime();
  414. if (!$model->save()) {
  415. throw new Exception(Form::formatErrorsForApi($model->getErrors()));
  416. }
  417. //暂写死
  418. if ($this->type == '758BF69C25C3422AA7743936BC77EE64') {
  419. if (!CompanyBank::find()->where('USER_ID=:USER_ID', [':USER_ID' => $model->USER_ID])->exists()) {
  420. $companyBank = new CompanyBank();
  421. $companyBank->USER_ID = $model->USER_ID;
  422. $companyBank->CREATE_ADMIN = \Yii::$app->user->id;
  423. $companyBank->CREATED_AT = Date::nowTime();
  424. $companyBank->UPDATED_AT = Date::nowTime();
  425. } else {
  426. $companyBank = CompanyBank::findOne(['USER_ID' => $model->USER_ID]);
  427. $companyBank->UPDATE_ADMIN = \Yii::$app->user->id;
  428. $companyBank->UPDATED_AT = Date::nowTime();
  429. }
  430. $companyBank->OPEN_NAME = $this->companyBank['openName'];
  431. $companyBank->OPEN_BANK = $this->companyBank['openBank'];
  432. $companyBank->BANK_ADDRESS = $this->companyBank['bankAddress'];
  433. $companyBank->BANK_NO = $this->companyBank['bankNo'];
  434. $companyBank->BANK_PROVINCE = $this->companyBank['bankAreaSelected'][0] ?? '0';
  435. $companyBank->BANK_CITY = $this->companyBank['bankAreaSelected'][1] ?? '0';
  436. $companyBank->BANK_COUNTY = $this->companyBank['bankAreaSelected'][2] ?? '0';
  437. $companyBank->REMARK = $this->createRemark;
  438. if (!$companyBank->save()) {
  439. throw new Exception(Form::formatErrorsForApi($companyBank->getErrors()));
  440. }
  441. }
  442. //写入会员信息
  443. if ($this->auditStatus == 'true') {
  444. $baseInfo = Info::baseInfoZh($model->USER_ID);
  445. //更改了注册类型
  446. if ($baseInfo['REG_TYPE'] != $model->REG_TYPE) {
  447. UserInfo::updateAll(['REG_TYPE' => $model->REG_TYPE, 'SHOULD_REG_TYPE' => $model->REG_TYPE, 'REG_NAME' => $model->REG_NAME, 'CREDIT_CODE' => $model->CREDIT_CODE, 'PREMISES' => $model->PREMISES, 'LEGAL_PERSON' => $model->LEGAL_PERSON, 'REG_EXPIRES' => $model->REG_EXPIRES], 'USER_ID=:USER_ID', [':USER_ID' => $model->USER_ID]);
  448. } else {
  449. UserInfo::updateAll(['REG_NAME' => $model->REG_NAME, 'REG_TYPE' => $model->REG_TYPE, 'CREDIT_CODE' => $model->CREDIT_CODE, 'PREMISES' => $model->PREMISES, 'LEGAL_PERSON' => $model->LEGAL_PERSON, 'REG_EXPIRES' => $model->REG_EXPIRES], 'USER_ID=:USER_ID', [':USER_ID' => $model->USER_ID]);
  450. }
  451. }
  452. $transaction->commit();
  453. } catch (Exception $e) {
  454. $transaction->rollBack();
  455. $this->addError('audit', $e->getMessage());
  456. return null;
  457. }
  458. return $model;
  459. }
  460. /**
  461. * 删除
  462. * @param $selected
  463. * @throws Exception
  464. */
  465. public static function delete($selected) {
  466. }
  467. }