Finance.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qisse
  5. * Date: 2017/6/27
  6. * Time: 20:02
  7. */
  8. namespace app\master\logic;
  9. use app\core\model\InterestType;
  10. use app\core\model\SubjectStat;
  11. use app\core\model\SubjectType;
  12. use app\core\model\Subject as Model;
  13. use app\core\model\User;
  14. use app\core\model\Cang;
  15. use think\Db;
  16. use tool\Common;
  17. class Finance extends Base
  18. {
  19. /**
  20. * @api {post} subject/getSubjectTypeList 得到产品类型列表
  21. * @apiVersion 1.0.0
  22. * @apiName getSubjectTypeList
  23. * @apiDescription 得到产品类型列表
  24. * @apiGroup Subject
  25. *
  26. * @apiSuccess {Object[]} subjectTypeList 产品类型列表
  27. * @apiSuccess {Number} subjectTypeList.subjectTypeID 产品类型ID
  28. * @apiSuccess {String} subjectTypeList.name 产品名称
  29. * @apiSuccessExample {json} 返回json数据(举例):
  30. {
  31. "code": 1,
  32. "msg": "操作成功",
  33. "content": {
  34. "subjectTypeList": [
  35. {
  36. "subjectTypeID":1,
  37. "name":"满标计息"
  38. }
  39. ]
  40. }
  41. }
  42. * @apiUse CreateUserError
  43. */
  44. public function getSubjectTypeList() {
  45. $subjectTypeList = SubjectType::all();
  46. return Common::rm(1, '操作成功', [
  47. 'subjectTypeList'=>$subjectTypeList
  48. ]);
  49. }
  50. /**
  51. * @api {post} subject/getInterestTypeList 得到计息类型列表
  52. * @apiVersion 1.0.0
  53. * @apiName getInterestTypeList
  54. * @apiDescription 得到计息类型列表
  55. * @apiGroup Subject
  56. *
  57. * @apiSuccess {Object[]} interestTypeList 计息类型列表
  58. * @apiSuccess {Number} interestTypeList.interestTypeID 计息类型ID
  59. * @apiSuccess {String} interestTypeList.name 计息类型名称
  60. *
  61. * @apiSuccessExample {json} 返回json数据(举例):
  62. {
  63. "code": 1,
  64. "msg": "操作成功",
  65. "content": {
  66. "interestTypeList": [
  67. {
  68. "interestTypeID": 1,
  69. "name": "一次付本息"
  70. }
  71. ]
  72. }
  73. }
  74. * @apiUse CreateUserError
  75. */
  76. public function getInterestTypeList() {
  77. $interestTypeList = InterestType::all();
  78. return Common::rm(1, '操作成功', [
  79. 'interestTypeList'=>$interestTypeList
  80. ]);
  81. }
  82. /**
  83. * @api {post} subject/getStatusList 得到产品状态列表
  84. * @apiVersion 1.0.0
  85. * @apiName getStatusList
  86. * @apiDescription 得到产品状态列表
  87. * @apiGroup Subject
  88. *
  89. *
  90. * @apiSuccess {Object[]} statusList 状态列表
  91. * @apiSuccess {Number} statusList.status 状态ID
  92. * @apiSuccess {String} statusList.statusText 状态名称
  93. * @apiSuccessExample {json} 返回json数据(举例):
  94. {
  95. "code": 1,
  96. "msg": "操作成功",
  97. "content": {
  98. "statusList": [
  99. {
  100. "status":1,
  101. "statusText":"注册"
  102. }
  103. ]
  104. }
  105. }
  106. * @apiUse CreateUserError
  107. */
  108. public function getStatusList() {
  109. $statusList = Model::STATUSS;
  110. return Common::rm(1, '操作成功', [
  111. 'statusList'=>$statusList
  112. ]);
  113. }
  114. /**
  115. * @api {post} subject/getStatusLoanList 得到产品放款状态列表
  116. * @apiVersion 1.0.0
  117. * @apiName getStatusLoanList
  118. * @apiDescription 得到产品放款状态列表
  119. * @apiGroup Subject
  120. *
  121. * @apiSuccess {Object[]} statusLoanList 放款状态列表
  122. * @apiSuccess {Number} statusLoanList.statusLoan 放款状态ID
  123. * @apiSuccess {String} statusLoanList.statusLoanText 放款状态名称
  124. * @apiSuccessExample {json} 返回json数据(举例):
  125. {
  126. "code": 1,
  127. "msg": "操作成功",
  128. "content": {
  129. "statusLoanList": [
  130. {
  131. "statusLoan":1,
  132. "statusLoanText":"已放款"
  133. }
  134. ]
  135. }
  136. }
  137. * @apiUse CreateUserError
  138. */
  139. public function getStatusLoanList() {
  140. $statusLoanList = Model::STATUS_LOANS;
  141. return Common::rm(1, '操作成功', [
  142. 'statusLoanList'=>$statusLoanList
  143. ]);
  144. }
  145. /**
  146. * @api {post} subject/getFinanceList 条件得到产品列表
  147. * @apiVersion 1.0.0
  148. * @apiName getFinanceList
  149. * @apiDescription 条件得到产品列表
  150. * @apiGroup Finance
  151. *
  152. * @apiParam {String} [overTimeFrom] 到期时间范围开始
  153. * @apiParam {String} [overTimeTo] 到期时间范围结束
  154. * @apiParam {Number} [status] 产品状态,为0为全部状态
  155. * @apiParam {Number} [statusLoan] 放款状态,为0为全部状态
  156. * @apiParam {Number} [pageIndex=1] 页码,从1开始
  157. * @apiParam {Number} [pageItemCount=10] 每页条数
  158. * @apiParam {String} [keyword] 关键字
  159. * @apiParamExample {json} 发送报文:
  160. {
  161. "overTimeFrom": "2016-12-20",
  162. "overTimeTo": "2018-12-20",
  163. "status": 0,
  164. "statusLoan": 0,
  165. "pageIndex": 1
  166. }
  167. *
  168. * @apiSuccess {Object[]} subjectList 产品列表
  169. * @apiSuccess {Number} subjectList.subjectID 产品ID
  170. * @apiSuccess {Number} subjectList.term 投标期数
  171. * @apiSuccess {String} subjectList.title 标题
  172. * @apiSuccess {String} subjectList.price 总金额
  173. * @apiSuccess {String} subjectList.year 年化
  174. * @apiSuccess {String} subjectList.basePrice 起投金额
  175. * @apiSuccess {String} subjectList.addTime 产品添加时间
  176. * @apiSuccess {String} subjectList.updateTime 更新时间
  177. * @apiSuccess {String} subjectList.baseMaxPrice 最大投资额
  178. * @apiSuccess {String} subjectList.overTime 产品到期时间,新增时为必传字段,更新时无效
  179. * @apiSuccess {String} subjectList.fullTime 满标时间
  180. * @apiSuccess {String} subjectList.overTime 产品到期时间
  181. * @apiSuccess {String} subjectList.repayTime 还款时间
  182. * @apiSuccess {String} subjectList.reachTime 到账时间
  183. * @apiSuccess {String} subjectList.status 产品状态,
  184. * @apiSuccess {String} subjectList.statusText 产品状态描述
  185. * @apiSuccess {String} subjectList.statusLoan 放款状态,
  186. * @apiSuccess {String} subjectList.statusLoanText 放款状态描述
  187. * @apiSuccess {Object} subjectList.subjectType 项目类型
  188. * @apiSuccess {Number} subjectList.subjectType.subjectTypeID 新手理财ID
  189. * @apiSuccess {String} subjectList.subjectType.name 名称
  190. * @apiSuccess {Object} subjectList.interestType 计息类型
  191. * @apiSuccess {Number} subjectList.interestType.interestTypeID 计息类型ID
  192. * @apiSuccess {String} subjectList.interestType.name 名称
  193. * @apiSuccess {Object} subjectList.interestTimeType 计息时间类型
  194. * @apiSuccess {Number} subjectList.interestTimeType.interestTypeID 计息时间类型ID
  195. * @apiSuccess {String} subjectList.interestTimeType.name 名称
  196. * @apiSuccess {Number} subjectList.isIndexApp 是否为app首页
  197. * @apiSuccess {Number} subjectList.isIndexPc 是否为PC首页
  198. * @apiSuccess {Number} subjectList.loanID 借款ID
  199. * @apiSuccess {Object} subjectList.subjectStat 投资统计
  200. * @apiSuccess {String} subjectList.subjectStat.moneyTotalInvest 总共已投资
  201. * @apiSuccess {Number} subjectList.subjectStat.timesInvest 已投资次数
  202. * @apiSuccess {Number} count 查询到条目总数
  203. * @apiSuccess {Number} pageItemCount 每页条数
  204. * @apiSuccessExample {json} 返回json数据(举例):
  205. {
  206. "code": 1,
  207. "msg": "操作成功",
  208. "content": {
  209. "subjectList": [
  210. {
  211. "subjectID": 33,
  212. "term": 15,
  213. "title": "新手标4567",
  214. "price": "100000.00",
  215. "year": "12.00",
  216. "basePrice": "1000.00",
  217. "baseMaxPrice": "100000.00",
  218. "addTime": "2017-12-18 17:38:30",
  219. "updateTime": "2017-12-18 19:24:41",
  220. "isIndexApp": 1,
  221. "isIndexPc": 0,
  222. "status": 2,
  223. "alias": "20171218173830mlh3vY",
  224. "loanID": 0,
  225. "hongbao": 0,
  226. "overTime": "2018-01-02",
  227. "fullTime": "2015-01-01 22:33:33",
  228. "statusLoan": 1,
  229. "subjectType": {
  230. "subjectTypeID": 1,
  231. "name": "新手理财"
  232. },
  233. "interestType": {
  234. "interestTypeID": 1,
  235. "name": "一次性还本付息"
  236. },
  237. "interestTimeType": {
  238. "interestTimeTypeID": 1,
  239. "name": "满标计息"
  240. },
  241. "subjectStat": {
  242. "moneyTotalInvest": "0.00",
  243. "timesInvest": 0
  244. },
  245. "statusText": "发布审核中",
  246. "repayTime": "2018-01-02",
  247. "reachTime": "2018-01-03",
  248. "statusLoanText": "未到放款时间"
  249. }
  250. ],
  251. "count": 18,
  252. "pageItemCount": 10
  253. }
  254. }
  255. * @apiUse CreateUserError
  256. */
  257. public function getFinanceList() {
  258. $map = [];
  259. if( isset($this->app['addTimeTo']) &&
  260. isset($this->app['addTimeFrom'])) {
  261. $map['addTime'] = ['between time', [$this->app['addTimeFrom'],$this->app['addTimeTo']]];
  262. }
  263. /*if($this->app['repayTimeFrom'] && $this->app['repayTimeTo']) {
  264. $map['repayTime'] = ['between', [$this->app['repayTimeFrom'],$this->app['repayTimeTo']]];
  265. }
  266. if($this->app['repayTimeFrom'] && $this->app['repayTimeTo']) {
  267. $map['repayTime'] = ['between', [$this->app['repayTimeFrom'],$this->app['repayTimeTo']]];
  268. }*/
  269. if(isset($this->app['subjectTypeID']) && $this->app['subjectTypeID']) {
  270. $map['subjectTypeID'] = $this->app['subjectTypeID'];
  271. }
  272. if(isset($this->app['status']) && $this->app['status']) {
  273. $map['status'] = $this->app['status'];
  274. }
  275. if(isset($this->app['statusLoan']) && $this->app['statusLoan']) {
  276. $map['statusLoan'] = $this->app['statusLoan'];
  277. }
  278. if(isset($this->app['keyword']) && $this->app['keyword']) {
  279. $map['subjectTypeID|title'] = ['like', '%'.$this->app['keyword'].'%'];
  280. }
  281. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  282. $this->app['pageIndex'] = 1;
  283. }
  284. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  285. $this->app['pageItemCount'] = 10;
  286. }
  287. $count = Model::where($map)->count();
  288. $list = Model::with('subjectType,interestType,interestTimeType,subjectStat')->where($map)->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
  289. if($list->isEmpty()) {
  290. return Common::rm(-2, '数据为空');
  291. }
  292. $list->append(['statusText','repayTime','reachTime','statusLoanText'])->hidden(['multiplePrice','operation','yearSystem','beginTime','endTime','subjectTypeID','interestTypeID','interestTimeTypeID',
  293. 'subjectStat'=>[
  294. 'subjectID','subjectStatID'
  295. ]
  296. ]);
  297. return Common::rm(1, '操作成功', [
  298. 'subjectList'=>$list,
  299. 'count'=>$count,
  300. 'pageItemCount'=>$this->app['pageItemCount']
  301. ]);
  302. }
  303. /**
  304. * @api {post} subject/getDetail 得到产品详细
  305. * @apiVersion 1.0.0
  306. * @apiName getDetail
  307. * @apiDescription 得到产品详细,返回参数释义请参照产品列表
  308. * @apiGroup Subject
  309. *
  310. * @apiParam {Number} subjectID 产品ID
  311. * @apiParamExample {json} 发送报文:
  312. {
  313. "subjectID": 12
  314. }
  315. *
  316. * @apiSuccessExample {json} 返回json数据(举例):
  317. {
  318. "code": 1,
  319. "msg": "操作成功",
  320. "content": {
  321. "detail": {
  322. "term": 15,
  323. "title": "新手标4567",
  324. "price": "100000.00",
  325. "year": "12.00",
  326. "basePrice": "1000.00",
  327. "baseMaxPrice": "100000.00",
  328. "addTime": "2017-12-18 17:38:30",
  329. "updateTime": "2017-12-20 15:25:24",
  330. "isIndexApp": 1,
  331. "isIndexPc": 0,
  332. "status": 3,
  333. "alias": "20171218173830mlh3vY",
  334. "loanID": 0,
  335. "overTime": "2018-01-02",
  336. "statusLoan": 1,
  337. "subjectType": {
  338. "subjectTypeID": 1,
  339. "name": "新手理财"
  340. },
  341. "interestType": {
  342. "interestTypeID": 1,
  343. "name": "一次性还本付息"
  344. },
  345. "interestTimeType": {
  346. "interestTimeTypeID": 1,
  347. "name": "一次性还本付息"
  348. },
  349. "subjectStat": {
  350. "moneyTotalInvest": "0.00",
  351. "timesInvest": 0
  352. },
  353. "statusText": "抢购中",
  354. "repayTime": "2018-01-02"
  355. }
  356. }
  357. }
  358. * @apiUse CreateUserError
  359. */
  360. public function getDetail() {
  361. $item = $this->getItem();
  362. if(!$item) {
  363. return Common::rm(-2, '没有数据');
  364. }
  365. $item->hidden(['operation','fullTime','hongbao','multiplePrice','yearSystem','beginTime','endTime']);
  366. return Common::rm(1, '操作成功', [
  367. 'detail'=>$item
  368. ]);
  369. }
  370. /**
  371. * @api {post} subject/update 新增/更新产品统一接口
  372. * @apiVersion 1.0.0
  373. * @apiName update
  374. * @apiDescription 新增/更新产品统一接口
  375. * @apiGroup Subject
  376. *
  377. * @apiParam {Number} subjectID 产品类型ID,更新时为必传字段,新增时保持subjectID必须为0
  378. * @apiParam {Number} subjectTypeID 产品类型ID,新增时为必传字段,更新时无效
  379. * @apiParam {Number} interestTypeID 计息类型ID,新增时为必传字段,更新时无效
  380. * @apiParam {Number} term 投标期数,新增时为必传字段,更新时无效
  381. * @apiParam {String} title 标题
  382. * @apiParam {String} price 总金额,新增时为必传字段,更新时无效
  383. * @apiParam {String} year 年化,新增时为必传字段,更新时无效
  384. * @apiParam {String} basePrice 起投金额
  385. * @apiParam {String} baseMaxPrice 最大投资额
  386. * @apiParam {String} overTime 产品到期时间,新增时为必传字段,更新时无效
  387. * @apiParam {Number} isIndexApp 是否为app首页
  388. * @apiParam {Number} isIndexPc 是否为PC首页
  389. * @apiParam {Number} loanID 借款ID,新增时为必传字段,更新时无效
  390. * @apiParamExample {json} 发送报文:
  391. {
  392. "subjectID": 2,
  393. "subjectTypeID": 12,
  394. "interestTypeID": 13,
  395. "term": 120,
  396. "year": "12.8",
  397. "price": "100000.00",
  398. "basePrice": "100.00",
  399. "baseMaxPrice": "100000.00",
  400. "overTime": "2014-10-10",
  401. "isIndexApp": 1,
  402. "isIndexPc": 1,
  403. "loanID": 12
  404. }
  405. *
  406. * @apiSuccess {Number} subjectID 更新产品ID
  407. * @apiSuccessExample {json} 返回json数据(举例):
  408. {
  409. "code": 1,
  410. "msg": "操作成功",
  411. "content": {
  412. "subjectID": 12
  413. }
  414. }
  415. * @apiUse CreateUserError
  416. */
  417. public function update()
  418. {
  419. if(!isset($this->app['subjectID']) ||!$this->app['subjectID']) {
  420. $model = Model::create([
  421. 'subjectTypeID' => $this->app['subjectTypeID'],
  422. 'interestTypeID' => $this->app['interestTypeID'],
  423. 'interestTimeTypeID'=> Model::getDefaultInterestTimeType(),
  424. 'term' => $this->app['term'],
  425. 'title' => $this->app['title'],
  426. 'price'=>$this->app['price'],
  427. 'year' => $this->app['year'],
  428. /*'yearSystem' => $this->app['yearSystem'],*/
  429. 'basePrice'=> $this->app['basePrice'],
  430. 'baseMaxPrice' => $this->app['baseMaxPrice'],
  431. /*'multiplePrice' => isset($this->app['multiplePrice']) ? $this->app['multiplePrice'] : 0,*/
  432. /*'beginTime'=>Common::datetotime($this->app['beginTime']),
  433. 'endTime' => Common::datetotime($this->app['endTime']),*/
  434. /*'repayBenTime' => Common::datetotime($this->app['repayTime']),
  435. 'repayInterestTime' => $this->app['interestTypeID'] == 2 ? 0 : Common::datetotime($this->app['repayTime']),*/
  436. 'overTime' => Common::datetotime($this->app['overTime']),
  437. 'isIndexApp'=>$this->app['isIndexApp'],
  438. 'isIndexPc'=>$this->app['isIndexPc'],
  439. 'status'=>Model::STATUS_ONLINE_CHECK,
  440. 'alias'=>Model::createAlias(),
  441. /*'loanID'=>$this->app['loanID'],*/
  442. 'statusLoan'=>1
  443. ]);
  444. SubjectStat::create([
  445. 'subjectID' => $model['subjectID']
  446. ]);
  447. }
  448. else {
  449. $model = Model::update([
  450. 'title' => $this->app['title'],
  451. 'basePrice'=> $this->app['basePrice'],
  452. 'baseMaxPrice' => $this->app['baseMaxPrice'],
  453. 'isIndexApp'=>$this->app['isIndexApp'],
  454. 'isIndexPc'=>$this->app['isIndexPc']
  455. ], [
  456. 'subjectID'=>$this->app['subjectID']
  457. ]);
  458. $model['subjectID'] = $this->app['subjectID'];
  459. }
  460. return Common::rm(1, '操作成功', [
  461. 'subjectID'=>$model['subjectID']
  462. ]);
  463. }
  464. public function getList() {
  465. $map = [];
  466. if($this->app['addTimeFrom'] && $this->app['addTimeTo']) {
  467. $map['addTime'] = ['between', [$this->app['addTimeFrom'],$this->app['addTimeTo']]];
  468. }
  469. if($this->app['repayTimeFrom'] && $this->app['repayTimeTo']) {
  470. $map['repayTime'] = ['between', [$this->app['repayTimeFrom'],$this->app['repayTimeTo']]];
  471. }
  472. if($this->app['repayTimeFrom'] && $this->app['repayTimeTo']) {
  473. $map['repayTime'] = ['between', [$this->app['repayTimeFrom'],$this->app['repayTimeTo']]];
  474. }
  475. if($this->app['subjectTypeID']) {
  476. $map['subjectTypeID'] = $this->app['subjectTypeID'];
  477. }
  478. if($this->app['status']) {
  479. $map['status'] = $this->app['status'];
  480. }
  481. $list = Model::with('subjectType,interestType,interestTimeType,subjectStat')->where($map)->order('addTime desc')->select();
  482. if($list->isEmpty()) {
  483. return Common::rm(-2, '数据为空');
  484. }
  485. $list->append(['statusText','repayTime','reachTime'])->hidden(['subjectID','subjectTypeID','interestTypeID','interestTimeTypeID',
  486. 'subjectStat'=>[
  487. 'subjectID','subjectStatID'
  488. ]
  489. ]);
  490. return Common::rm(1, '操作成功', [
  491. 'list'=>$list
  492. ]);
  493. }
  494. /**
  495. * @api {post} subject/actionOnline A - 发布通过审核上线
  496. * @apiVersion 1.0.0
  497. * @apiName actionOnline
  498. * @apiDescription 发布通过审核上线
  499. * @apiGroup Subject
  500. *
  501. * @apiParam {Number} subjectID 产品ID
  502. * @apiParamExample {json} 发送报文:
  503. {
  504. "subjectID": 12
  505. }
  506. *
  507. * @apiSuccess {Number} subjectID 更新产品ID
  508. * @apiSuccessExample {json} 返回json数据(举例):
  509. {
  510. "code": 1,
  511. "msg": "操作成功",
  512. "content": {
  513. "status": 1,
  514. "statusText": "正在审核"
  515. }
  516. }
  517. * @apiUse CreateUserError
  518. */
  519. public function actionOnline() {
  520. $item = $this->getItem();
  521. if(!$item) {
  522. return Common::rm(-2, '没有数据');
  523. }
  524. if($item['status'] != 2) {
  525. return Common::rm(-3, '不是可以进行的状态,当前状态'.$item['statusText']);
  526. }
  527. $item['status'] = Model::STATUS_ONLINE;
  528. $item->save();
  529. return Common::rm(1, '操作成功', [
  530. 'detail'=>$item->append(['statusText'])->visible(['status'])
  531. ]);
  532. }
  533. /**
  534. * @api {post} subject/actionDelete 删除条目
  535. * @apiVersion 1.0.0
  536. * @apiName actionDelete
  537. * @apiDescription 删除条目
  538. * @apiGroup Subject
  539. *
  540. * @apiParam {Number} subjectID 产品ID
  541. * @apiParamExample {json} 发送报文:
  542. {
  543. "subjectID": 12
  544. }
  545. *
  546. * @apiSuccessExample {json} 返回json数据(举例):
  547. {
  548. "code": 1,
  549. "msg": "操作成功"
  550. }
  551. * @apiUse CreateUserError
  552. */
  553. public function actionDelete() {
  554. $model = Model::get($this->app['subjectID']);
  555. if($model['status'] != 2) {
  556. return Common::rm(-3, '当前产品状态不允许删除');
  557. }
  558. $model->delete();
  559. return Common::rm(1, '操作成功');
  560. }
  561. /**
  562. * @api {post} subject/actionForged 虚拟认购
  563. * @apiVersion 1.0.0
  564. * @apiName actionForged
  565. * @apiDescription 虚拟认购
  566. * @apiGroup Subject
  567. *
  568. * @apiParam {Number} subjectID 产品ID
  569. * @apiParam {String} moneySubject 投资金额
  570. * @apiParamExample {json} 发送报文:
  571. {
  572. "subjectID": 12,
  573. "moneySubject":"100000.00"
  574. }
  575. *
  576. * @apiSuccessExample {json} 返回json数据(举例):
  577. {
  578. "code": 1,
  579. "msg": "操作成功"
  580. }
  581. * @apiUse CreateUserError
  582. */
  583. public function actionForged() {
  584. //第零步,判断该产品是否符合投资要求
  585. $model = Model::get($this->app['subjectID']);
  586. if($model['status'] == Model::STATUS_FULL) {
  587. return Common::rm(-4, '该商品已经满标,不能投资了');
  588. }
  589. if($model['status'] == Model::STATUS_ONLINE_CHECK || $model['status'] == Model::STATUS_LOCK) {
  590. return Common::rm(-5, '该商品已经下架,不能投资了');
  591. }
  592. if($model['basePrice'] > $this->app['moneySubject']) {
  593. return Common::rm(-6, '最低需投资'.$model['basePrice']);
  594. }
  595. if($model['baseMaxPrice'] < $this->app['moneySubject']) {
  596. return Common::rm(-7, '投资最大不得超出'.$model['baseMaxPrice']);
  597. }
  598. if($model->subjectStat['moneyTotalInvest'] + $this->app['moneySubject'] > $model['price']) {
  599. return Common::rm(-8, '投入金额过多,超出标的总金额,最多可投'.($model['price'] - $model->subjectStat['moneyTotalInvest']));
  600. }
  601. //第一步,得到一个虚拟账户
  602. $userList = User::where([
  603. 'isForged'=>1
  604. ])->field(['userID'])->select();
  605. if($userList->isEmpty()) {
  606. return Common::rm(-3, '不存在虚拟账户');
  607. }
  608. $userIDS = array_column($userList->toArray(), 'userID');
  609. $userIDIndex = mt_rand(0, count($userIDS) - 1);
  610. $userID = $userIDS[$userIDIndex];
  611. $user = User::get($userID);
  612. //第二步,保存一个仓
  613. $cang = Cang::create([
  614. 'subjectID' => $this->app['subjectID'],
  615. 'userID' => $user['userID'],
  616. 'moneySubject' => $this->app['moneySubject'],
  617. 'ben' => $this->app['moneySubject'],
  618. 'status'=>Cang::STATUS_PAY,
  619. 'isForged'=>1
  620. ]);
  621. $cang['alias'] = Cang::createAlias($cang['cangID']);
  622. $cang->save();
  623. //第三步,对产品进行统计
  624. SubjectStat::where([
  625. 'subjectID'=>$this->app['subjectID']
  626. ])->setInc('moneyTotalInvest', $this->app['moneySubject'] * 100);
  627. SubjectStat::where([
  628. 'subjectID'=>$this->app['subjectID']
  629. ])->setInc('timesInvest');
  630. //第四步,判断是否满标
  631. if($model->subjectStat['moneyTotalInvest'] + $this->app['moneySubject'] == $model['price']) {
  632. //如果满标了,设置满标
  633. Model::setSubjectFull($model);
  634. }
  635. return Common::rm(1, '操作成功', [
  636. 'detail'=>$this->getItem()
  637. ]);
  638. }
  639. private function getItem($map = []) {
  640. $map['subjectID'] = $this->app['subjectID'];
  641. $item= Model::with('subjectType,interestType,interestTimeType,subjectStat')->where($map)->find();
  642. if(!$item) {
  643. return false;
  644. }
  645. $item->append(['statusText','repayTime'])->hidden(['subjectID','subjectTypeID','interestTypeID','interestTimeTypeID',
  646. 'subjectStat'=>[
  647. 'subjectID','subjectStatID'
  648. ]
  649. ]);
  650. return $item;
  651. }
  652. public function init() {
  653. User::destroy([
  654. 'watchID'=>$this->app['watchID']
  655. ]);
  656. return Common::rm(1, '操作成功');
  657. }
  658. public function getUserByWatchID()
  659. {
  660. $model = User::get([
  661. 'watchID'=>$this->app['watchID']
  662. ]);
  663. if(!$model) {
  664. return Common::rm(-1, '不存在');
  665. }
  666. $model->append([
  667. 'userID'
  668. ])->visible([
  669. 'status',
  670. 'height',
  671. 'weight',
  672. 'gender',
  673. 'trueName'
  674. ]);
  675. return Common::rm(1, '操作成功', [
  676. 'user'=>$model
  677. ]);
  678. }
  679. }