Notify.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. <?php
  2. /**
  3. * 发送
  4. * User: qissen
  5. * Date: 2017/11/26
  6. * Time: 11:26a
  7. */
  8. namespace app\crontab\command;
  9. use app\core\model\Bank;
  10. use app\core\model\CangRepay;
  11. use app\core\model\Channel;
  12. use app\core\model\Hongbao;
  13. use app\core\model\Loan;
  14. use app\core\model\Subject;
  15. use app\core\model\SubjectStat;
  16. use app\core\model\User;
  17. use app\core\model\Cang as CangModel;
  18. use app\core\model\UserAccount;
  19. use app\core\model\UserBank;
  20. use app\core\model\UserDrawcash;
  21. use app\core\model\UserHongbao;
  22. use app\core\model\UserRecharge;
  23. use think\console\Command;
  24. use think\console\Input;
  25. use think\console\Output;
  26. use think\Db;
  27. use think\Log;
  28. use tool\Common;
  29. class Notify extends Command
  30. {
  31. private $db_config_from = [
  32. // 数据库类型
  33. 'type' => 'mysql',
  34. // 服务器地址
  35. 'hostname' => 'rm-bp1m6abztwo27gum6.mysql.rds.aliyuncs.com',
  36. // 数据库名
  37. 'database' => 'goldapi',
  38. // 数据库用户名
  39. 'username' => 'sqlyog',
  40. // 数据库密码
  41. 'password' => 'Qissen111111',
  42. // 数据库编码默认采用utf8
  43. 'charset' => 'utf8',
  44. // 数据库表前缀
  45. 'prefix' => 's_',
  46. ];
  47. private $db_config_to = [
  48. // 数据库类型
  49. 'type' => 'mysql',
  50. // 服务器地址
  51. 'hostname' => 'rm-bp1cy713yknm2326x.mysql.rds.aliyuncs.com',
  52. // 数据库名
  53. 'database' => 'p2p',
  54. // 数据库用户名
  55. 'username' => 'sqlyog',
  56. // 数据库密码
  57. 'password' => 'Qissen111111',
  58. // 数据库编码默认采用utf8
  59. 'charset' => 'utf8',
  60. // 数据库表前缀
  61. 'prefix' => 'a_',
  62. ];
  63. protected function configure()
  64. {
  65. $this->setName('Notify')->setDescription('Notify开始');
  66. }
  67. protected function execute(Input $input, Output $output)
  68. {
  69. Log::info('Notify:'.Common::timetodate(THINK_START_TIME));
  70. //执行顺序不能变
  71. $this->DY_subject();
  72. //$this->DY_user();
  73. //$this->DY_bank();
  74. //$this->DY_recharge();
  75. //$this->DY_drawcash();
  76. //$this->DY_hongbao();
  77. //$this->loan();
  78. //$this->user();
  79. $output->writeln("Notify结束");
  80. }
  81. private function DY_channel() {
  82. //Log::info(Db::connect($this->db_config_from)->query('select * from s_constant'));
  83. $from_channelList = Db::connect($this->db_config_from)->query('select * from s_constant where parent_id=9');
  84. $to_data = [];
  85. foreach ($from_channelList as $k=>$item) {
  86. $to_data[$k]['name'] = $item['cons_key'];
  87. $to_data[$k]['code'] = $item['cons_value'];
  88. $to_data[$k]['addTime'] = Common::datetotime($item['add_time']);
  89. $to_data[$k]['type'] = 1;
  90. }
  91. (new Channel())->insertAll($to_data);
  92. //Db::connect($this->db_config_to);
  93. }
  94. private function DY_hongbao() {
  95. $perCount = 100;
  96. for($i = 0; $i < 5000; $i++) {
  97. $from_list = Db::connect($this->db_config_from)->query('select id,user_id,title,min_due,min_invest,amount,create_time,expire_time,status from s_user_redenvelope '.' LIMIT '.($i * $perCount).','.$perCount);
  98. foreach ($from_list as $k => $item) {
  99. $user = User::get([
  100. 'BACKUPID' => $item['user_id']
  101. ]);
  102. if(!$user) {
  103. continue;
  104. }
  105. $hongbao = Hongbao::get([
  106. 'title' => $item['title'],
  107. 'minDay' => $item['min_due'],
  108. 'minMoney' => $item['min_invest'] * 100,
  109. 'money' => $item['amount'] * 100
  110. ]);
  111. if(!$hongbao) {
  112. continue;
  113. }
  114. //用户
  115. $userHongbao = UserHongbao::get([
  116. 'BACKUPID' => $item['id']
  117. ]);
  118. if (!$userHongbao) {
  119. $userHongbao = new UserHongbao();
  120. }
  121. $status = 0;
  122. if ($item['status'] == 0) {
  123. $status = UserHongbao::STATUS_UNUSED;
  124. } else if ($item['status'] == 1) {
  125. $status = UserHongbao::STATUS_USED;
  126. } else if ($item['status'] == 2) {
  127. $status = UserHongbao::STATUS_OUTTIME;
  128. }
  129. $userHongbao['BACKUPID'] = $item['id'];
  130. $userHongbao['hongbaoID'] = $hongbao['hongbaoID'];
  131. $userHongbao['userID'] = $user['userID'];
  132. $userHongbao['getType'] = 1;
  133. $userHongbao['status'] = $status;
  134. $userHongbao['hongbaoPlanID'] = 5;
  135. $userHongbao['addTime'] = Common::datetotime($item['create_time']);
  136. $userHongbao['beginTime'] = Common::datetotime($item['create_time']);
  137. $userHongbao['endTime'] = Common::datetotime($item['expire_time']);
  138. $userHongbao->save();
  139. }
  140. }
  141. }
  142. private function DY_user() {
  143. $perCount = 100;
  144. for($i = 0; $i < 300; $i++) {
  145. $from_list = Db::connect($this->db_config_from)->query('select * from s_user where card_no_auth=1 LIMIT '.($i * $perCount).','.$perCount);
  146. foreach ($from_list as $k=>$item) {
  147. //用户
  148. $user = User::get([
  149. 'mobile'=>$item['username']
  150. ]);
  151. if(!$user) {
  152. $user = new User();
  153. }
  154. $user['BACKUPID'] = $item['id'];//BACKUPID
  155. $user['mobile'] = $item['username'];//手机号
  156. $user['trueName'] = $item['real_name'];//真实姓名
  157. $user['isAuthTrueName'] = $item['card_no_auth'];//实名认证
  158. $user['isAuthBank'] = $item['card_no_auth'];//实名认证
  159. $user['passport'] = $item['card_no'];//身份证
  160. $user['email'] = $item['email'];//银行卡认证
  161. if($item['level'] == 2) {
  162. $user['isNewInvest'] = 1;
  163. }
  164. $channel = Channel::get([
  165. 'code'=>$item['channel']
  166. ]);
  167. if($channel) {
  168. $user['channelID'] = $channel['channelID'];//渠道名称
  169. if($item['channel_web_id'] == 40) {
  170. $user['channelID'] = 59;
  171. }
  172. }
  173. else {
  174. $item['channel_web_id'] = 0;
  175. }
  176. if($item['add_time']) {
  177. $user['addTime'] = Common::datetotime($item['add_time']);//添加时间
  178. }
  179. else {
  180. $user['addTime'] = 0;//添加时间
  181. }
  182. $user->save();
  183. //账户
  184. $from_account = Db::connect($this->db_config_from)->query('select * from s_user_account where user_id='.$item['id']);
  185. $account = UserAccount::get([
  186. 'userID'=>$user['userID']
  187. ]);
  188. if(!$account) {
  189. $account = new UserAccount();
  190. }
  191. if(isset($from_account[0])) {
  192. $account['BACKUPID'] = $from_account[0]['id'];
  193. $account['userID'] = $user['userID'];
  194. $account['money'] = $from_account[0]['account_able'];
  195. $account['moneyAcc'] = $from_account[0]['total_invest_interest'];
  196. $account['moneyFrozen'] = $from_account[0]['account_freeze'];
  197. //$to_data['moneyYesterday'] = $account[''];
  198. //$to_data['moneyToday'] = $account[''];
  199. $account['waitBen'] = $from_account[0]['wait_capital'];
  200. $account['waitInterest'] = $from_account[0]['wait_interest'];
  201. $account['hasInvestBenTotal'] = 0;
  202. $account['hasInvestMoneyTotal'] = 0;
  203. $account['hasRepayBenTotal'] = $from_account[0]['total_invest_capital'];
  204. $account['hasRepayInterestTotal'] = $from_account[0]['total_invest_interest'];
  205. $account->save();
  206. }
  207. else {
  208. $account['userID'] = $from_account[0]['user_id'];
  209. $account->save();
  210. }
  211. //新增银行卡
  212. }
  213. }
  214. }
  215. private function DY_bank() {
  216. $from_list = Db::connect($this->db_config_from)->query('select * from s_user_bank');
  217. foreach ($from_list as $k=>$item) {
  218. //用户
  219. $user = User::get([
  220. 'BACKUPID'=>$item['user_id']
  221. ]);
  222. if(!$user) {
  223. continue;
  224. }
  225. //银行
  226. $bank = Bank::get([
  227. 'bankAccountCode'=>$item['bank_code']
  228. ]);
  229. //用户银行卡
  230. $userBank = UserBank::get([
  231. 'BACKUPID'=>$item['id']
  232. ]);
  233. if(!$userBank) {
  234. $userBank = new UserBank();
  235. }
  236. $userBank['BACKUPID'] = $item['id'];//BACKUPID
  237. $userBank['userID'] = $user['userID'];//手机号
  238. $userBank['bankNameFull'] = $item['bank_name'];//
  239. $userBank['bankID'] = isset($bank['bankID']) ? $bank['bankID'] : 0;//实名认证
  240. $userBank['bankNameFull'] = $item['bank_name'];
  241. $userBank['bankAccount'] = $item['acct_name'];
  242. $userBank['bankNumber'] = $item['bank_card_no'];
  243. $userBank['trueName'] = $item['acct_name'];
  244. $userBank['mobile'] = $item['mobile'];
  245. $userBank['addTime'] = Common::datetotime($item['add_time']);
  246. $userBank['status'] = 1;
  247. $userBank['isDefault'] = 1;
  248. $userBank->save();
  249. }
  250. }
  251. private function DY_recharge() {
  252. $from_list = Db::connect($this->db_config_from)->query('select * from s_user_wallet_records where recharge_no<>\'\' and value > 0 and type=1');
  253. foreach ($from_list as $k=>$item) {
  254. //用户
  255. $user = User::get([
  256. 'BACKUPID'=>$item['user_id']
  257. ]);
  258. if(!$user || $item['user_id'] == 0) {
  259. continue;
  260. }
  261. //银行
  262. $userBank = UserBank::get([
  263. 'BACKUPID'=>$item['user_bank_id']
  264. ]);
  265. if(!$userBank) {
  266. continue;
  267. }
  268. //余额
  269. $userRecharge = UserRecharge::get([
  270. 'BACKUPID'=>$item['id']
  271. ]);
  272. if(!$userRecharge) {
  273. $userRecharge = new UserRecharge();
  274. }
  275. $status = 0;
  276. if($item['status'] == 1) {
  277. $status = UserRecharge::STATUS_PAY;
  278. }
  279. else if($item['status'] == 2) {
  280. $status = UserRecharge::STATUS_UNPAY;
  281. }
  282. else if($item['status'] == 3) {
  283. $status = UserRecharge::STATUS_ERROR;
  284. }
  285. $userRecharge['BACKUPID'] = $item['id'];
  286. $userRecharge['userID'] = $user['userID'];
  287. $userRecharge['money'] = $item['value'];
  288. $userRecharge['status'] = $status;
  289. $userRecharge['outerNumber'] = $item['recharge_no'].'-'.$item['trade_no'];
  290. $userRecharge['type'] = 'TYPE_BANK';
  291. $userRecharge['bankID'] = $userBank['bankID'];
  292. $userRecharge['bankAccount'] = $userBank['bankAccount'];
  293. $userRecharge['bankNumber'] = $userBank['bankNumber'];
  294. $userRecharge['bankName'] = $userBank['bankNameFull'];
  295. $userRecharge['addTime'] = Common::datetotime($item['add_time']);
  296. $userRecharge['trueName'] = $userBank['trueName'];
  297. $userRecharge['mobile'] = $userBank['mobile'];
  298. $userRecharge['userBankID'] = $userBank['userBankID'];
  299. $userRecharge->save();
  300. }
  301. }
  302. private function DY_drawcash() {
  303. $from_list = Db::connect($this->db_config_from)->query('select * from s_user_wallet_records where recharge_no<>\'\' and value < 0 and type=2');
  304. foreach ($from_list as $k=>$item) {
  305. //用户
  306. $user = User::get([
  307. 'BACKUPID'=>$item['user_id']
  308. ]);
  309. if(!$user || $item['user_id'] == 0) {
  310. continue;
  311. }
  312. //银行
  313. $userBank = UserBank::get([
  314. 'BACKUPID'=>$item['user_bank_id']
  315. ]);
  316. if(!$userBank) {
  317. continue;
  318. }
  319. //余额
  320. $userDrawcash = UserDrawcash::get([
  321. 'BACKUPID'=>$item['id']
  322. ]);
  323. if(!$userDrawcash) {
  324. $userDrawcash = new UserDrawcash();
  325. }
  326. $status = 0;
  327. if($item['status'] == 1) {
  328. $status = UserDrawcash::STATUS_OK;
  329. }
  330. else if($item['status'] == 2) {
  331. $status = UserDrawcash::STATUS_ING;
  332. }
  333. else if($item['status'] == 3) {
  334. $status = UserDrawcash::STATUS_ERROR;
  335. }
  336. $userDrawcash['BACKUPID'] = $item['id'];
  337. $userDrawcash['userID'] = $user['userID'];
  338. $userDrawcash['money'] = $item['value'];
  339. $userDrawcash['status'] = $status;
  340. $userDrawcash['outerNumber'] = $item['recharge_no'].'-'.$item['trade_no'];
  341. $userDrawcash['type'] = 'TYPE_BANK';
  342. $userDrawcash['bankID'] = $userBank['bankID'];
  343. $userDrawcash['bankAccount'] = $userBank['bankAccount'];
  344. $userDrawcash['bankNumber'] = $userBank['bankNumber'];
  345. $userDrawcash['bankName'] = $userBank['bankNameFull'];
  346. $userDrawcash['applyTime'] = Common::datetotime($item['add_time']);
  347. $userDrawcash['trueName'] = $userBank['trueName'];
  348. $userDrawcash['mobile'] = $userBank['mobile'];
  349. $userDrawcash['userBankID'] = $userBank['userBankID'];
  350. $userDrawcash->save();
  351. }
  352. }
  353. private function DY_recharge1() {
  354. $from_list = Db::connect($this->db_config_from)->query('select * from s_recharge_log');
  355. foreach ($from_list as $k=>$item) {
  356. //用户
  357. $user = User::get([
  358. 'BACKUPID'=>$item['user_id']
  359. ]);
  360. if(!$user || $item['user_id'] == 0) {
  361. continue;
  362. }
  363. //银行
  364. $userBank = UserBank::get([
  365. 'bankNumber'=>$item['card_no']
  366. ]);
  367. //余额
  368. $userRecharge = UserRecharge::get([
  369. 'BACKUPID'=>$item['id']
  370. ]);
  371. if(!$userRecharge) {
  372. $userRecharge = new UserRecharge();
  373. }
  374. $userRecharge['BACKUPID'] = $item['id'];//BACKUPID
  375. $userRecharge['userID'] = $user['userID'];//手机号
  376. $userRecharge['money'] = $item['amount'];//
  377. $userRecharge['status'] = 1;
  378. $userRecharge['type'] = 'TYPE_BANK';
  379. $userRecharge['bankID'] = $userBank['bankID'];
  380. $userRecharge['bankAccount'] = $userBank['bankAccount'];
  381. $userRecharge['bankNumber'] = $userBank['bankNumber'];
  382. $userRecharge['bankName'] = $userBank['bankName'];
  383. $userRecharge['addTime'] = Common::datetotime($item['add_time']);
  384. $userRecharge['trueName'] = $userBank['trueName'];
  385. $userRecharge['mobile'] = $userBank['mobile'];
  386. $userRecharge['userBankID'] = $userBank['userBankID'];
  387. $userRecharge->save();
  388. }
  389. }
  390. private function DY_loan() {
  391. $from_contractList = Db::connect($this->db_config_from)->query('select * from s_contract');
  392. foreach ($from_contractList as $k=>$item) {
  393. $loan = Loan::get([
  394. 'alias'=>$item['name']
  395. ]);
  396. if(!$loan) {
  397. $loan = new Loan();
  398. }
  399. $loan['alias'] = $item['name'];
  400. $loan['beginTime'] = $item['start_time'];
  401. $loan['endTime'] = $item['end_time'];
  402. $loan['money'] = $item['price'];
  403. $loan['year'] = $item['interest'];
  404. $loan['name'] = $item['financing'];
  405. $loan['addTime'] = $item['add_time'];
  406. $loan['certType'] = 1;
  407. $loan['certContent'] = $item['idcard'];
  408. $loan['status'] = 1;
  409. $loan['pledgeType'] = 1;
  410. $loan->save();
  411. }
  412. }
  413. private function DY_subject() {
  414. $from_subjectList = Db::connect($this->db_config_from)->query('select * from s_project where amount > 0');
  415. foreach ($from_subjectList as $k=>$item) {
  416. $subjectTypeID = 1;
  417. if($item['type'] == 4) {
  418. $subjectTypeID = 1;
  419. }
  420. else if($item['type'] == 5) {
  421. $subjectTypeID = 2;
  422. }
  423. else if($item['type'] == 6) {
  424. $subjectTypeID = 3;
  425. }
  426. else if($item['type'] == 7) {
  427. $subjectTypeID = 4;
  428. }
  429. $status = Subject::STATUS_ONLINE_CHECK;
  430. $statusLoan = Subject::STATUS_LOAN_NULL;
  431. if($item['status'] == 1) {
  432. $status = Subject::STATUS_ONLINE_CHECK;
  433. }
  434. else if($item['status'] == 2) {
  435. $status = Subject::STATUS_ONLINE;
  436. }
  437. else if($item['status'] == 3) {
  438. $status = Subject::STATUS_FULL;
  439. $statusLoan = Subject::STATUS_LOAN_FANG_WAIT;
  440. }
  441. else if($item['status'] == 4) {
  442. $status = Subject::STATUS_FULL;
  443. $statusLoan = Subject::STATUS_LOAN_FANG_WAIT;
  444. }
  445. else if($item['status'] == 5) {
  446. $status = Subject::STATUS_REPAY;
  447. }
  448. else if($item['status'] == 6) {
  449. $status = Subject::STATUS_FULL;
  450. $statusLoan = Subject::STATUS_LOAN_FANG;
  451. }
  452. else if($item['status'] == 7) {
  453. $status = Subject::STATUS_FULL;
  454. $statusLoan = Subject::STATUS_LOAN_FANG;
  455. }
  456. $subject = Subject::get([
  457. 'BACKUPID'=>$item['id']
  458. ]);
  459. if(!$subject) {
  460. $subject = new Subject();
  461. }
  462. $loan = Loan::get([
  463. 'alias'=>$item['contract_no']
  464. ]);
  465. $subject['BACKUPID'] = $item['id'];
  466. $subject['title'] = $item['title'];
  467. $subject['subjectTypeID'] = $subjectTypeID;
  468. $subject['interestTypeID'] = 1;
  469. $subject['interestTimeTypeID'] = 2;
  470. $subject['term'] = $item['duration'];
  471. $subject['price'] = $item['amount'];
  472. $subject['year'] = $item['user_interest'];
  473. $subject['yearSystem'] = isset($item['user_platform_subsidy']) ? $item['user_platform_subsidy'] : 0;
  474. $subject['basePrice'] = $item['money_min'];
  475. $subject['baseMaxPrice'] = $item['money_max'];
  476. $subject['multiplePrice'] = 0;
  477. $subject['releaseTime'] = Common::datetotime($item['start_time']);
  478. /*$subject['beginTime'] = Common::datetotime($item['start_time']);
  479. $subject['endTime'] = Common::datetotime($item['end_time']);*/
  480. $subject['isIndexApp'] = 0;
  481. $subject['isIndexPc'] = 0;
  482. $subject['status'] = $status;
  483. $subject['statusLoan'] = $statusLoan;
  484. $subject['loanID'] = $loan ? $loan['alias'] : 0;
  485. $subject['hongbao'] = '';
  486. $subject['overTime'] = Common::datetotime($item['end_time']);
  487. $subject['fullTime'] = isset($item['soldout_time']) ? $item['soldout_time'] : 0;
  488. $subject['stage'] = $item['stage'];
  489. //dump($subject);exit;
  490. //dump($subject);exit;
  491. $subject->save();
  492. //$from_account = Db::connect($this->db_config_from)->query('select * from s_user_account where user_id='.$item['id']);
  493. $subjectStat = SubjectStat::get([
  494. 'subjectID'=>$subject['subjectID']
  495. ]);
  496. if(!$subjectStat) {
  497. $subjectStat = new SubjectStat();
  498. }
  499. $subjectStat['subjectID'] = $subject['subjectID'];
  500. $subjectStat['moneyTotalInvest'] = $item['amount'] - $item['able'];
  501. $subjectStat['timesInvest'] = 0;
  502. $subjectStat->save();
  503. }
  504. }
  505. private function DY_cang() {
  506. $from_cangList = Db::connect($this->db_config_from)->query('select * from s_user_due_detail');
  507. foreach ($from_cangList as $k=>$item) {
  508. $subject = Subject::get([
  509. 'BACKUPID'=>$item['project_id']
  510. ]);
  511. $user = User::get([
  512. 'BACKUPID'=>$item['user_id']
  513. ]);
  514. $status = 0;
  515. if($item['status'] == 1) {
  516. $status = CangModel::STATUS_INTEREST;
  517. }
  518. else if($item['status'] == 2) {
  519. $status = CangModel::STATUS_FINISH;
  520. }
  521. else if($item['type'] == 3) {
  522. $status = CangModel::STATUS_REPAY;
  523. }
  524. $from_recharge = Db::connect($this->db_config_from)->query('select * from s_recharge_log where recharge_no=\''.$item['recharge_no'].'\''.' and user_id='.$item['user_id'].' and project_id='.$item['project_id']);
  525. if(!$from_recharge) {
  526. continue;
  527. }
  528. $from_recharge = $from_recharge[0];
  529. $cang = CangModel::get([
  530. 'BACKUPID'=>$item['id']
  531. ]);
  532. if(!$cang) {
  533. $cang = new CangModel();
  534. }
  535. $cang['BACKUPID'] = $item['id'];
  536. $cang['subjectID'] = $subject['subjectID'];
  537. $cang['userID'] = $user['userID'];
  538. $cang['moneySubject'] = $item['due_capital'];
  539. $cang['status'] = $status;
  540. $cang['addTime'] = $item['user_interest'];
  541. $cang['payTime'] = isset($item['user_platform_subsidy']) ? $item['user_platform_subsidy'] : 0;
  542. $cang['updateTime'] = $item['money_min'];
  543. $cang['interestBeginTime'] = Common::datetotime($item['start_time']);
  544. $cang['interestEndTime'] = Common::datetotime($item['due_time']);
  545. $cang['repayTime'] = Common::datetotime($item['end_time']);
  546. $cang['year'] = $subject['year'];
  547. $cang['ben'] = $item['due_capital'];
  548. $cang['yearSystem'] = $subject['yearSystem'];
  549. $cang['interest'] = $item['due_interest'];
  550. $cang['investDay'] = $item['duration_day'];
  551. $cang['interestTimeTypeID'] = $subject['interestTimeTypeID'];
  552. if($item['ghost_phone']) {
  553. $cang['isForged'] = 1;
  554. $cang['userID'] = 4;
  555. }
  556. $cang['osType'] = $item['device_type'];
  557. if($item['device_type'] == 3) {
  558. $cang['osType'] = 4;
  559. }
  560. else if($item['device_type'] == 4) {
  561. $cang['osType'] = 3;
  562. }
  563. $cang['money'] = $from_recharge['amount'];
  564. $cang->save();
  565. $cangRepay = CangRepay::where([
  566. 'cangID'=>$cang['cangID']
  567. ])->select();
  568. if($cangRepay->isEmpty()) {
  569. $cangRepay = new CangRepay();
  570. }
  571. else {
  572. $cangRepay->destroy();
  573. }
  574. //生成本
  575. $cangRepay['money'] = $item['due_capital'];
  576. $cangRepay['repayTime'] = Common::datetotime($item['end_time']);
  577. $cangRepay['reachTime'] = Common::datetotime($item['end_time']) + 86400;
  578. $cangRepay['cangID'] = $cang['cangID'];
  579. $cangRepay['subjectID'] = $subject['subjectID'];
  580. $cangRepay['userID'] = $user['userID'];
  581. $cangRepay['status'] = CangRepay::STATUS_UNREPAY;
  582. if($item['status'] == 2) {
  583. $cangRepay['status'] = CangRepay::STATUS_REPAY;
  584. }
  585. $cangRepay['repayTypeID'] = 1;
  586. $cangRepay->save();
  587. //生成息
  588. $cangRepay['money'] = $item['due_interest'];
  589. $cangRepay['repayTime'] = Common::datetotime($item['end_time']);
  590. $cangRepay['reachTime'] = Common::datetotime($item['end_time']) + 86400;
  591. $cangRepay['cangID'] = $cang['cangID'];
  592. $cangRepay['subjectID'] = $subject['subjectID'];
  593. $cangRepay['userID'] = $user['userID'];
  594. $cangRepay['status'] = CangRepay::STATUS_UNREPAY;
  595. if($item['status'] == 2) {
  596. $cangRepay['status'] = CangRepay::STATUS_REPAY;
  597. }
  598. $cangRepay['repayTypeID'] = 2;
  599. $cangRepay->isUpdate(false)->save();
  600. //生成流水
  601. }
  602. }
  603. }