Subject.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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\exception\AppException;
  10. use app\core\model\Fang;
  11. use app\core\model\InterestType;
  12. use app\core\model\SubjectStat;
  13. use app\core\model\SubjectType;
  14. use app\core\model\Subject as Model;
  15. use app\core\model\User;
  16. use app\core\model\Cang;
  17. use app\core\model\UserBank;
  18. use app\core\model\UserHongbao;
  19. use app\core\service\Finance as FinanceService;
  20. use think\Db;
  21. use think\Exception;
  22. use think\Log;
  23. use tool\Common;
  24. class Subject extends Base
  25. {
  26. /**
  27. * @api {post} subject/getSubjectTypeList 得到产品类型列表
  28. * @apiVersion 1.0.0
  29. * @apiName getSubjectTypeList
  30. * @apiDescription 得到产品类型列表
  31. * @apiGroup Subject
  32. *
  33. * @apiSuccess {Object[]} subjectTypeList 产品类型列表
  34. * @apiSuccess {Number} subjectTypeList.subjectTypeID 产品类型ID
  35. * @apiSuccess {String} subjectTypeList.name 产品名称
  36. * @apiSuccessExample {json} 返回json数据(举例):
  37. {
  38. "code": 1,
  39. "msg": "操作成功",
  40. "content": {
  41. "subjectTypeList": [
  42. {
  43. "subjectTypeID":1,
  44. "name":"满标计息"
  45. }
  46. ]
  47. }
  48. }
  49. * @apiUse CreateUserError
  50. */
  51. public function getSubjectTypeList() {
  52. $subjectTypeList = SubjectType::all();
  53. return Common::rm(1, '操作成功', [
  54. 'subjectTypeList'=>$subjectTypeList
  55. ]);
  56. }
  57. /**
  58. * @api {post} subject/getInterestTypeList 得到计息类型列表
  59. * @apiVersion 1.0.0
  60. * @apiName getInterestTypeList
  61. * @apiDescription 得到计息类型列表
  62. * @apiGroup Subject
  63. *
  64. * @apiSuccess {Object[]} interestTypeList 计息类型列表
  65. * @apiSuccess {Number} interestTypeList.interestTypeID 计息类型ID
  66. * @apiSuccess {String} interestTypeList.name 计息类型名称
  67. *
  68. * @apiSuccessExample {json} 返回json数据(举例):
  69. {
  70. "code": 1,
  71. "msg": "操作成功",
  72. "content": {
  73. "interestTypeList": [
  74. {
  75. "interestTypeID": 1,
  76. "name": "一次付本息"
  77. }
  78. ]
  79. }
  80. }
  81. * @apiUse CreateUserError
  82. */
  83. public function getInterestTypeList() {
  84. $interestTypeList = InterestType::all();
  85. return Common::rm(1, '操作成功', [
  86. 'interestTypeList'=>$interestTypeList
  87. ]);
  88. }
  89. /**
  90. * @api {post} subject/getStatusList 得到产品状态列表
  91. * @apiVersion 1.0.0
  92. * @apiName getStatusList
  93. * @apiDescription 得到产品状态列表
  94. * @apiGroup Subject
  95. *
  96. *
  97. * @apiSuccess {Object[]} statusList 状态列表
  98. * @apiSuccess {Number} statusList.status 状态ID
  99. * @apiSuccess {String} statusList.statusText 状态名称
  100. * @apiSuccessExample {json} 返回json数据(举例):
  101. {
  102. "code": 1,
  103. "msg": "操作成功",
  104. "content": {
  105. "statusList": [
  106. {
  107. "status":1,
  108. "statusText":"注册"
  109. }
  110. ]
  111. }
  112. }
  113. * @apiUse CreateUserError
  114. */
  115. public function getStatusList() {
  116. $statusList = Model::STATUSS;
  117. return Common::rm(1, '操作成功', [
  118. 'statusList'=>$statusList
  119. ]);
  120. }
  121. /**
  122. * @api {post} subject/getStatusLoanList 得到产品放款状态列表
  123. * @apiVersion 1.0.0
  124. * @apiName getStatusLoanList
  125. * @apiDescription 得到产品放款状态列表
  126. * @apiGroup Subject
  127. *
  128. * @apiSuccess {Object[]} statusLoanList 放款状态列表
  129. * @apiSuccess {Number} statusLoanList.statusLoan 放款状态ID
  130. * @apiSuccess {String} statusLoanList.statusLoanText 放款状态名称
  131. * @apiSuccessExample {json} 返回json数据(举例):
  132. {
  133. "code": 1,
  134. "msg": "操作成功",
  135. "content": {
  136. "statusLoanList": [
  137. {
  138. "statusLoan":1,
  139. "statusLoanText":"已放款"
  140. }
  141. ]
  142. }
  143. }
  144. * @apiUse CreateUserError
  145. */
  146. public function getStatusLoanList() {
  147. $statusLoanList = Model::STATUS_LOANS;
  148. return Common::rm(1, '操作成功', [
  149. 'statusLoanList'=>$statusLoanList
  150. ]);
  151. }
  152. /**
  153. * @api {post} subject/getSubjectList 条件得到产品列表
  154. * @apiVersion 1.0.0
  155. * @apiName getSubjectList
  156. * @apiDescription 条件得到产品列表
  157. * @apiGroup Subject
  158. *
  159. * @apiParam {String} [overTimeFrom] 到期时间范围开始
  160. * @apiParam {String} [overTimeTo] 到期时间范围结束
  161. * @apiParam {Number} [status] 产品状态,为0为全部状态
  162. * @apiParam {Number} [statusLoan] 放款状态,为0为全部状态
  163. * @apiParam {Number} [pageIndex=1] 页码,从1开始
  164. * @apiParam {Number} [pageItemCount=10] 每页条数
  165. * @apiParam {String} [keyword] 关键字
  166. * @apiParamExample {json} 发送报文:
  167. {
  168. "overTimeFrom": "2016-12-20",
  169. "overTimeTo": "2018-12-20",
  170. "status": 0,
  171. "statusLoan": 0,
  172. "pageIndex": 1
  173. }
  174. *
  175. * @apiSuccess {Object[]} subjectList 产品列表
  176. * @apiSuccess {Number} subjectList.subjectID 产品ID
  177. * @apiSuccess {Number} subjectList.term 投标期数
  178. * @apiSuccess {String} subjectList.title 标题
  179. * @apiSuccess {String} subjectList.price 总金额
  180. * @apiSuccess {String} subjectList.year 年化
  181. * @apiSuccess {String} subjectList.basePrice 起投金额
  182. * @apiSuccess {String} subjectList.addTime 产品添加时间
  183. * @apiSuccess {String} subjectList.updateTime 更新时间
  184. * @apiSuccess {String} subjectList.baseMaxPrice 最大投资额
  185. * @apiSuccess {String} subjectList.overTime 产品到期时间,新增时为必传字段,更新时无效
  186. * @apiSuccess {String} subjectList.fullTime 满标时间
  187. * @apiSuccess {String} subjectList.overTime 产品到期时间
  188. * @apiSuccess {String} subjectList.repayTime 还款时间
  189. * @apiSuccess {String} subjectList.reachTime 到账时间
  190. * @apiSuccess {String} subjectList.status 产品状态,
  191. * @apiSuccess {String} subjectList.statusText 产品状态描述
  192. * @apiSuccess {String} subjectList.statusLoan 放款状态,
  193. * @apiSuccess {String} subjectList.statusLoanText 放款状态描述
  194. * @apiSuccess {Object} subjectList.subjectType 项目类型
  195. * @apiSuccess {Number} subjectList.subjectType.subjectTypeID 新手理财ID
  196. * @apiSuccess {String} subjectList.subjectType.name 名称
  197. * @apiSuccess {Object} subjectList.interestType 计息类型
  198. * @apiSuccess {Number} subjectList.interestType.interestTypeID 计息类型ID
  199. * @apiSuccess {String} subjectList.interestType.name 名称
  200. * @apiSuccess {Object} subjectList.interestTimeType 计息时间类型
  201. * @apiSuccess {Number} subjectList.interestTimeType.interestTypeID 计息时间类型ID
  202. * @apiSuccess {String} subjectList.interestTimeType.name 名称
  203. * @apiSuccess {Number} subjectList.isIndexApp 是否为app首页
  204. * @apiSuccess {Number} subjectList.isIndexPc 是否为PC首页
  205. * @apiSuccess {Number} subjectList.loanID 借款ID
  206. * @apiSuccess {Object} subjectList.subjectStat 投资统计
  207. * @apiSuccess {String} subjectList.subjectStat.moneyTotalInvest 总共已投资
  208. * @apiSuccess {Number} subjectList.subjectStat.timesInvest 已投资次数
  209. * @apiSuccess {Number} count 查询到条目总数
  210. * @apiSuccess {Number} pageItemCount 每页条数
  211. * @apiSuccessExample {json} 返回json数据(举例):
  212. {
  213. "code": 1,
  214. "msg": "操作成功",
  215. "content": {
  216. "subjectList": [
  217. {
  218. "subjectID": 33,
  219. "term": 15,
  220. "title": "新手标4567",
  221. "price": "100000.00",
  222. "year": "12.00",
  223. "basePrice": "1000.00",
  224. "baseMaxPrice": "100000.00",
  225. "addTime": "2017-12-18 17:38:30",
  226. "updateTime": "2017-12-18 19:24:41",
  227. "isIndexApp": 1,
  228. "isIndexPc": 0,
  229. "status": 2,
  230. "alias": "20171218173830mlh3vY",
  231. "loanID": 0,
  232. "hongbao": 0,
  233. "overTime": "2018-01-02",
  234. "fullTime": "2015-01-01 22:33:33",
  235. "statusLoan": 1,
  236. "subjectType": {
  237. "subjectTypeID": 1,
  238. "name": "新手理财"
  239. },
  240. "interestType": {
  241. "interestTypeID": 1,
  242. "name": "一次性还本付息"
  243. },
  244. "interestTimeType": {
  245. "interestTimeTypeID": 1,
  246. "name": "满标计息"
  247. },
  248. "subjectStat": {
  249. "moneyTotalInvest": "0.00",
  250. "timesInvest": 0
  251. },
  252. "statusText": "发布审核中",
  253. "repayTime": "2018-01-02",
  254. "reachTime": "2018-01-03",
  255. "statusLoanText": "未到放款时间"
  256. }
  257. ],
  258. "count": 18,
  259. "pageItemCount": 10
  260. }
  261. }
  262. * @apiUse CreateUserError
  263. */
  264. public function getSubjectList() {
  265. $map = [];
  266. if( isset($this->app['overTimeTo']) &&
  267. isset($this->app['overTimeFrom'])) {
  268. $map['overTime'] = ['between time', [$this->app['overTimeFrom'],$this->app['overTimeTo']]];
  269. }
  270. /*if($this->app['repayTimeFrom'] && $this->app['repayTimeTo']) {
  271. $map['repayTime'] = ['between', [$this->app['repayTimeFrom'],$this->app['repayTimeTo']]];
  272. }
  273. if($this->app['repayTimeFrom'] && $this->app['repayTimeTo']) {
  274. $map['repayTime'] = ['between', [$this->app['repayTimeFrom'],$this->app['repayTimeTo']]];
  275. }*/
  276. if(isset($this->app['subjectTypeID']) && $this->app['subjectTypeID']) {
  277. $map['subjectTypeID'] = $this->app['subjectTypeID'];
  278. }
  279. if(isset($this->app['status']) && $this->app['status']) {
  280. $map['status'] = $this->app['status'];
  281. }
  282. if(isset($this->app['statusLoan']) && $this->app['statusLoan']) {
  283. $map['statusLoan'] = $this->app['statusLoan'];
  284. }
  285. if(isset($this->app['keyword']) && $this->app['keyword']) {
  286. $map['title'] = ['like', '%'.$this->app['keyword'].'%'];
  287. }
  288. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  289. $this->app['pageIndex'] = 1;
  290. }
  291. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  292. $this->app['pageItemCount'] = 10;
  293. }
  294. $count = Model::where($map)->count();
  295. $list = Model::with(['subjectType','interestType','interestTimeType','subjectStat', 'cangList'=>function($query){
  296. $query->where('isForged', 0);
  297. }])->where($map)->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('listOrder desc,isShow desc,addTime desc')->select();
  298. if($list->isEmpty()) {
  299. return Common::rm(-2, '数据为空');
  300. }
  301. $list->append(['statusText','repayTime','reachTime','statusLoanText'])->hidden(['multiplePrice','operation','yearSystem','beginTime','endTime','subjectTypeID','interestTypeID','interestTimeTypeID',
  302. 'subjectStat'=>[
  303. 'subjectID','subjectStatID'
  304. ]
  305. ]);
  306. foreach ($list as $k=>$item) {
  307. $list[$k]['fangTotal'] = 0;
  308. foreach ($list[$k]['cangList'] as $_k=>$_item) {
  309. $list[$k]['fangTotal'] += $_item['moneySubject'];
  310. }
  311. }
  312. //得到余额
  313. $finance = new FinanceService();
  314. $result = $finance->balance($msg, '15825631526');
  315. return Common::rm(1, '操作成功', [
  316. 'subjectList'=>$list,
  317. 'count'=>$count,
  318. 'moneyFang'=>$result['money'],
  319. 'pageItemCount'=>$this->app['pageItemCount']
  320. ]);
  321. }
  322. /**
  323. * @api {post} subject/getDetail 得到产品详细
  324. * @apiVersion 1.0.0
  325. * @apiName getDetail
  326. * @apiDescription 得到产品详细,返回参数释义请参照产品列表
  327. * @apiGroup Subject
  328. *
  329. * @apiParam {Number} subjectID 产品ID
  330. * @apiParamExample {json} 发送报文:
  331. {
  332. "subjectID": 12
  333. }
  334. *
  335. * @apiSuccessExample {json} 返回json数据(举例):
  336. {
  337. "code": 1,
  338. "msg": "操作成功",
  339. "content": {
  340. "detail": {
  341. "term": 15,
  342. "title": "新手标4567",
  343. "price": "100000.00",
  344. "year": "12.00",
  345. "basePrice": "1000.00",
  346. "baseMaxPrice": "100000.00",
  347. "addTime": "2017-12-18 17:38:30",
  348. "updateTime": "2017-12-20 15:25:24",
  349. "isIndexApp": 1,
  350. "isIndexPc": 0,
  351. "status": 3,
  352. "alias": "20171218173830mlh3vY",
  353. "loanID": 0,
  354. "overTime": "2018-01-02",
  355. "statusLoan": 1,
  356. "subjectType": {
  357. "subjectTypeID": 1,
  358. "name": "新手理财"
  359. },
  360. "interestType": {
  361. "interestTypeID": 1,
  362. "name": "一次性还本付息"
  363. },
  364. "interestTimeType": {
  365. "interestTimeTypeID": 1,
  366. "name": "一次性还本付息"
  367. },
  368. "subjectStat": {
  369. "moneyTotalInvest": "0.00",
  370. "timesInvest": 0
  371. },
  372. "statusText": "抢购中",
  373. "repayTime": "2018-01-02"
  374. }
  375. }
  376. }
  377. * @apiUse CreateUserError
  378. */
  379. public function getDetail() {
  380. $item = $this->getItem();
  381. if(!$item) {
  382. return Common::rm(-2, '没有数据');
  383. }
  384. $item->hidden(['operation','fullTime','hongbao','multiplePrice','yearSystem','beginTime','endTime']);
  385. return Common::rm(1, '操作成功', [
  386. 'detail'=>$item
  387. ]);
  388. }
  389. /**
  390. * @api {post} subject/update 新增/更新产品统一接口
  391. * @apiVersion 1.0.0
  392. * @apiName update
  393. * @apiDescription 新增/更新产品统一接口
  394. * @apiGroup Subject
  395. *
  396. * @apiParam {Number} subjectID 产品类型ID,更新时为必传字段,新增时保持subjectID必须为0
  397. * @apiParam {Number} subjectTypeID 产品类型ID,新增时为必传字段,更新时无效
  398. * @apiParam {Number} interestTypeID 计息类型ID,新增时为必传字段,更新时无效
  399. * @apiParam {Number} term 投标期数,新增时为必传字段,更新时无效
  400. * @apiParam {String} title 标题
  401. * @apiParam {String} price 总金额,新增时为必传字段,更新时无效
  402. * @apiParam {String} year 年化,新增时为必传字段,更新时无效
  403. * @apiParam {String} basePrice 起投金额
  404. * @apiParam {String} baseMaxPrice 最大投资额
  405. * @apiParam {String} overTime 产品到期时间,新增时为必传字段,更新时无效
  406. * @apiParam {Number} isIndexApp 是否为app首页
  407. * @apiParam {Number} isIndexPc 是否为PC首页
  408. * @apiParam {Number} loanID 借款ID,新增时为必传字段,更新时无效
  409. * @apiParamExample {json} 发送报文:
  410. {
  411. "subjectID": 2,
  412. "subjectTypeID": 12,
  413. "interestTypeID": 13,
  414. "term": 120,
  415. "year": "12.8",
  416. "price": "100000.00",
  417. "basePrice": "100.00",
  418. "baseMaxPrice": "100000.00",
  419. "overTime": "2014-10-10",
  420. "isIndexApp": 1,
  421. "isIndexPc": 1,
  422. "loanID": 12
  423. }
  424. *
  425. * @apiSuccess {Number} subjectID 更新产品ID
  426. * @apiSuccessExample {json} 返回json数据(举例):
  427. {
  428. "code": 1,
  429. "msg": "操作成功",
  430. "content": {
  431. "subjectID": 12
  432. }
  433. }
  434. * @apiUse CreateUserError
  435. */
  436. public function update()
  437. {
  438. if(!isset($this->app['subjectID']) ||!$this->app['subjectID']) {
  439. $model = Model::create([
  440. 'subjectTypeID' => $this->app['subjectTypeID'],
  441. 'interestTypeID' => $this->app['interestTypeID'],
  442. 'interestTimeTypeID'=> Model::getDefaultInterestTimeType(),
  443. 'term' => $this->app['term'],
  444. 'title' => $this->app['title'],
  445. 'price'=>$this->app['price'],
  446. 'year' => $this->app['year'],
  447. /*'yearSystem' => $this->app['yearSystem'],*/
  448. 'basePrice'=> $this->app['basePrice'],
  449. /*'baseMaxPrice' => $this->app['baseMaxPrice'],*/
  450. 'baseMaxPrice' => $this->app['price'],
  451. 'isShow' => 1,
  452. 'releaseTime' => Common::datetotime($this->app['releaseTime']),
  453. /*'multiplePrice' => isset($this->app['multiplePrice']) ? $this->app['multiplePrice'] : 0,*/
  454. /*'beginTime'=>Common::datetotime($this->app['beginTime']),
  455. 'endTime' => Common::datetotime($this->app['endTime']),*/
  456. /*'repayBenTime' => Common::datetotime($this->app['repayTime']),
  457. 'repayInterestTime' => $this->app['interestTypeID'] == 2 ? 0 : Common::datetotime($this->app['repayTime']),*/
  458. 'overTime' => Common::datetotime(Common::timetodate(Common::datetotime($this->app['releaseTime']) + $this->app['term'] * 86400, 0)),
  459. 'isIndexApp'=>$this->app['isIndexApp'],
  460. 'isIndexPc'=>$this->app['isIndexPc'],
  461. 'status'=>Model::STATUS_ONLINE_CHECK,
  462. 'alias'=>Model::createAlias(),
  463. 'loanID'=>$this->app['loanID'],
  464. 'statusLoan'=>1
  465. ]);
  466. SubjectStat::create([
  467. 'subjectID' => $model['subjectID']
  468. ]);
  469. }
  470. else {
  471. $model = Model::update([
  472. 'title' => $this->app['title'],
  473. 'basePrice'=> $this->app['basePrice'],
  474. 'baseMaxPrice' => $this->app['baseMaxPrice'],
  475. 'isIndexApp'=>$this->app['isIndexApp'],
  476. 'isIndexPc'=>$this->app['isIndexPc'],
  477. 'loanID'=>$this->app['loanID'],
  478. 'releaseTime' => Common::datetotime($this->app['releaseTime']),
  479. 'overTime' => Common::datetotime(Common::timetodate(Common::datetotime($this->app['releaseTime']) + $this->app['term'] * 86400, 0)),
  480. ], [
  481. 'subjectID'=>$this->app['subjectID']
  482. ]);
  483. $model['subjectID'] = $this->app['subjectID'];
  484. }
  485. return Common::rm(1, '操作成功', [
  486. 'subjectID'=>$model['subjectID']
  487. ]);
  488. }
  489. public function getList() {
  490. $map = [];
  491. if($this->app['addTimeFrom'] && $this->app['addTimeTo']) {
  492. $map['addTime'] = ['between', [$this->app['addTimeFrom'],$this->app['addTimeTo']]];
  493. }
  494. if($this->app['repayTimeFrom'] && $this->app['repayTimeTo']) {
  495. $map['repayTime'] = ['between', [$this->app['repayTimeFrom'],$this->app['repayTimeTo']]];
  496. }
  497. if($this->app['repayTimeFrom'] && $this->app['repayTimeTo']) {
  498. $map['repayTime'] = ['between', [$this->app['repayTimeFrom'],$this->app['repayTimeTo']]];
  499. }
  500. if($this->app['subjectTypeID']) {
  501. $map['subjectTypeID'] = $this->app['subjectTypeID'];
  502. }
  503. if($this->app['status']) {
  504. $map['status'] = $this->app['status'];
  505. }
  506. $list = Model::with('subjectType,interestType,interestTimeType,subjectStat')->where($map)->order('addTime desc')->select();
  507. if($list->isEmpty()) {
  508. return Common::rm(-2, '数据为空');
  509. }
  510. $list->append(['statusText','repayTime','reachTime'])->hidden(['subjectID','subjectTypeID','interestTypeID','interestTimeTypeID',
  511. 'subjectStat'=>[
  512. 'subjectID','subjectStatID'
  513. ]
  514. ]);
  515. return Common::rm(1, '操作成功', [
  516. 'list'=>$list
  517. ]);
  518. }
  519. /**
  520. * @api {post} subject/actionOnline A - 发布通过审核上线
  521. * @apiVersion 1.0.0
  522. * @apiName actionOnline
  523. * @apiDescription 发布通过审核上线
  524. * @apiGroup Subject
  525. *
  526. * @apiParam {Number} subjectID 产品ID
  527. * @apiParamExample {json} 发送报文:
  528. {
  529. "subjectID": 12
  530. }
  531. *
  532. * @apiSuccess {Number} subjectID 更新产品ID
  533. * @apiSuccessExample {json} 返回json数据(举例):
  534. {
  535. "code": 1,
  536. "msg": "操作成功",
  537. "content": {
  538. "status": 1,
  539. "statusText": "正在审核"
  540. }
  541. }
  542. * @apiUse CreateUserError
  543. */
  544. /*public function actionOnline() {
  545. $item = $this->getItem();
  546. if($item['releaseTime'] == (Common::datetotime(Common::timetodate(THINK_START_TIME, 0)) + 86400)) {
  547. return Common::rm(-4, '不能人工发布第二天及第二天之后的标');
  548. }
  549. if(!$item) {
  550. return Common::rm(-2, '没有数据');
  551. }
  552. if($item['status'] != 2) {
  553. return Common::rm(-3, '不是可以进行的状态,当前状态'.$item['statusText']);
  554. }
  555. $item['status'] = Model::STATUS_ONLINE;
  556. $item->save();
  557. return Common::rm(1, '操作成功', [
  558. 'detail'=>$item->append(['statusText'])->visible(['status'])
  559. ]);
  560. }*/
  561. /**
  562. * @api {post} subject/actionDelete 删除条目
  563. * @apiVersion 1.0.0
  564. * @apiName actionDelete
  565. * @apiDescription 删除条目
  566. * @apiGroup Subject
  567. *
  568. * @apiParam {Number} subjectID 产品ID
  569. * @apiParamExample {json} 发送报文:
  570. {
  571. "subjectID": 12
  572. }
  573. *
  574. * @apiSuccessExample {json} 返回json数据(举例):
  575. {
  576. "code": 1,
  577. "msg": "操作成功"
  578. }
  579. * @apiUse CreateUserError
  580. */
  581. public function actionDelete() {
  582. $model = Model::get($this->app['subjectID']);
  583. if($model['status'] != 2) {
  584. return Common::rm(-3, '当前产品状态不允许删除');
  585. }
  586. $model->delete();
  587. return Common::rm(1, '操作成功');
  588. }
  589. /**
  590. * @api {post} subject/actionForged 虚拟认购
  591. * @apiVersion 1.0.0
  592. * @apiName actionForged
  593. * @apiDescription 虚拟认购
  594. * @apiGroup Subject
  595. *
  596. * @apiParam {Number} subjectID 产品ID
  597. * @apiParam {String} moneySubject 投资金额
  598. * @apiParamExample {json} 发送报文:
  599. {
  600. "subjectID": 12,
  601. "moneySubject":"100000.00"
  602. }
  603. *
  604. * @apiSuccessExample {json} 返回json数据(举例):
  605. {
  606. "code": 1,
  607. "msg": "操作成功"
  608. }
  609. * @apiUse CreateUserError
  610. */
  611. public function actionForged() {
  612. //第零步,判断该产品是否符合投资要求
  613. $model = Model::get($this->app['subjectID']);
  614. if($model['status'] == Model::STATUS_FULL) {
  615. return Common::rm(-4, '该商品已经满标,不能投资了');
  616. }
  617. if($model['status'] == Model::STATUS_ONLINE_CHECK || $model['status'] == Model::STATUS_LOCK) {
  618. return Common::rm(-5, '该商品已经下架,不能投资了');
  619. }
  620. if($model['basePrice'] > $this->app['moneySubject']) {
  621. return Common::rm(-6, '最低需投资'.$model['basePrice']);
  622. }
  623. if($model['baseMaxPrice'] < $this->app['moneySubject']) {
  624. return Common::rm(-7, '投资最大不得超出'.$model['baseMaxPrice']);
  625. }
  626. if($model->subjectStat['moneyTotalInvest'] + $this->app['moneySubject'] > $model['price']) {
  627. return Common::rm(-8, '投入金额过多,超出标的总金额,最多可投'.($model['price'] - $model->subjectStat['moneyTotalInvest']));
  628. }
  629. //第一步,得到一个虚拟账户
  630. $userList = User::where([
  631. 'isForged'=>1
  632. ])->field(['userID'])->select();
  633. if($userList->isEmpty()) {
  634. return Common::rm(-3, '不存在虚拟账户');
  635. }
  636. $userIDS = array_column($userList->toArray(), 'userID');
  637. $userIDIndex = mt_rand(0, count($userIDS) - 1);
  638. $userID = $userIDS[$userIDIndex];
  639. $user = User::get($userID);
  640. //第二步,保存一个仓
  641. $cang = Cang::create([
  642. 'subjectID' => $this->app['subjectID'],
  643. 'userID' => $user['userID'],
  644. 'moneySubject' => $this->app['moneySubject'],
  645. 'ben' => $this->app['moneySubject'],
  646. 'status'=>Cang::STATUS_PAY,
  647. 'isForged'=>1
  648. ]);
  649. $cang['alias'] = Cang::createAlias($cang['cangID']);
  650. $cang->save();
  651. //第三步,对产品进行统计
  652. SubjectStat::where([
  653. 'subjectID'=>$this->app['subjectID']
  654. ])->setInc('moneyTotalInvest', $this->app['moneySubject'] * 100);
  655. SubjectStat::where([
  656. 'subjectID'=>$this->app['subjectID']
  657. ])->setInc('timesInvest');
  658. //第四步,判断是否满标
  659. if($model->subjectStat['moneyTotalInvest'] + $this->app['moneySubject'] == $model['price']) {
  660. //如果满标了,设置满标
  661. Model::setSubjectFull($model);
  662. }
  663. return Common::rm(1, '操作成功', [
  664. 'detail'=>$this->getItem()
  665. ]);
  666. }
  667. /**
  668. * @api {post} subject/actionForged 放款
  669. * @apiVersion 1.0.0
  670. * @apiName actionForged
  671. * @apiDescription 虚拟认购
  672. * @apiGroup Subject
  673. *
  674. * @apiParam {Number} subjectID 产品ID
  675. * @apiParam {String} moneySubject 投资金额
  676. * @apiParamExample {json} 发送报文:
  677. {
  678. "subjectID": 12,
  679. "moneySubject":"100000.00"
  680. }
  681. *
  682. * @apiSuccessExample {json} 返回json数据(举例):
  683. {
  684. "code": 1,
  685. "msg": "操作成功"
  686. }
  687. * @apiUse CreateUserError
  688. */
  689. public function actionFang() {
  690. //第一步,得到subject
  691. $subject = Model::get($this->app['subjectID']);
  692. if(!$subject || $subject['statusLoan'] != Model::STATUS_LOAN_FANG_WAIT) {
  693. return Common::rm(-2, '不存在符合的产品');
  694. }
  695. $money = Common::price2(Cang::where([
  696. 'subjectID'=>$this->app['subjectID'],
  697. 'isForged'=>0
  698. ])->sum('moneySubject') / 100);
  699. //第二步,放款
  700. Db::startTrans();
  701. try {
  702. if($money > 0) {
  703. //生成fang
  704. $fang = Fang::Create([
  705. 'subjectID'=>$subject['subjectID'],
  706. 'loanID'=>$subject['loanID'],
  707. 'money'=>$money,
  708. 'operator'=>$this->master['mobile']
  709. ]);
  710. //同步金账户
  711. vendor('payModel.Trade');
  712. $finance = new FinanceService();
  713. $trade = new \Trade();
  714. $trade->setPayment('15825631526');
  715. $trade->setReceive('18989706775');
  716. $trade->setMoney($money);
  717. $result = $finance->order($msg, $trade);
  718. if(!$result) {
  719. Db::rollback();
  720. return Common::rm(-10, $msg);
  721. }
  722. //更新fang
  723. $fang['outerNumber'] = $result;
  724. $fang['outerName'] = $this->platform;
  725. $fang['outerUserFrom'] = '15825631526';
  726. $fang['outerUserTo'] = '18989706775';
  727. $fang->save();
  728. }
  729. $subject['statusLoan'] = Model::STATUS_LOAN_FANG;
  730. $subject->save();
  731. Db::commit();
  732. return Common::rm(1, '操作成功', [
  733. 'detail'=>$subject->append(['statusText', 'statusLoanText'])->visible(['status', 'statusLoan'])
  734. ]);
  735. }
  736. catch (Exception $e) {
  737. // 回滚事务
  738. Log::error($e->getMessage().'|'.$e->getLine().'|'.$e->getFile());
  739. Db::rollback();
  740. throw new AppException(-9, $e->getMessage());
  741. }
  742. }
  743. public function actionExport() {
  744. $model = Model::with([
  745. 'cangList'=>function($query) {
  746. $query->where([
  747. 'isForged'=>0
  748. ]);
  749. }
  750. ])->where([
  751. 'subjectID'=>$this->app['subjectID']
  752. ])->find();
  753. vendor('excel.PHPExcel');
  754. vendor('excel.PHPExcel_IOFactory');
  755. vendor('excel.PHPExcel_IOFactory');
  756. vendor('excel.PHPExcel.Style.PHPExcel_Style_NumberFormat');
  757. vendor('excel.PHPExcel.Style.Alignment');
  758. $objPHPExcel = new \PHPExcel();
  759. $objPHPExcel->getProperties()->setCreator("佳乾财富")->setLastModifiedBy("佳乾财富")->setTitle("title")->setSubject("subject")->setDescription("description")->setKeywords("keywords")->setCategory("Category");
  760. $objPHPExcel->setActiveSheetIndex(0)
  761. ->setTitle($model['title'])
  762. ->setCellValue("A2", "编号")
  763. ->setCellValue("B2", "外部流水号")
  764. ->setCellValue("C2", "手机号码")
  765. ->setCellValue("D2", "姓名")
  766. ->setCellValue("E2", "产品")
  767. ->setCellValue("F2", "应还总额")
  768. ->setCellValue("G2", "还款时间")
  769. ->setCellValue("H2", "投资份额")
  770. ->setCellValue("I2", "实投")
  771. ->setCellValue("J2", "总利息")
  772. ->setCellValue("K2", "红包")
  773. ->setCellValue("L2", "年化")
  774. ->setCellValue("M2", "加息券")
  775. ->setCellValue("N2", "下单时间")
  776. ->setCellValue("O2", "投资天数")
  777. ->setCellValue("P2", "状态")
  778. ->setCellValue("Q2", "银行卡")
  779. ->setCellValue("R2", "银行");
  780. $objPHPExcel->getActiveSheet()->getStyle('A1:R1')->getFont()->setName('宋体')->setSize(12)->setBold(true);
  781. $objPHPExcel->getActiveSheet()->getStyle('A1:R1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  782. $objPHPExcel->getActiveSheet()->getStyle('A1:R1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  783. $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(31.5);
  784. $objPHPExcel->getActiveSheet()->mergeCells('A1:R1')->setCellValue("A1", $model['title']);
  785. $objPHPExcel->getActiveSheet()->getStyle('A2:R2')->getFont()->setName('宋体')->setSize(11)->setBold(true);
  786. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
  787. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  788. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
  789. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(13);
  790. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
  791. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(10);
  792. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
  793. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(10);
  794. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(10);
  795. $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(10);
  796. $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(10);
  797. $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(10);
  798. $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(10);
  799. $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(18);
  800. $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(10);
  801. $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(10);
  802. $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(25);
  803. $objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(15);
  804. // 设置列表值
  805. $pos = 3;
  806. foreach ($model['cangList'] as $k => $item) {
  807. $hongbaoList = UserHongbao::where([
  808. 'userHongbaoID'=>['in', $model['hongbao']]
  809. ])->select();
  810. $hongbaoMoney = 0;
  811. foreach ($hongbaoList as $_item) {
  812. $hongbaoMoney += $_item['money'];
  813. }
  814. $jiaxi = 0;
  815. foreach ($hongbaoList as $_item) {
  816. $jiaxi += $_item['year'];
  817. }
  818. $user = User::get([
  819. 'userID'=>$item['userID'],
  820. 'isForged'=>0
  821. ]);
  822. $objPHPExcel->getActiveSheet()->setCellValue("A".$pos, $item['cangID']);
  823. $objPHPExcel->getActiveSheet()->setCellValue("B".$pos, $item['outerNumber']);
  824. $objPHPExcel->getActiveSheet()->setCellValue("C".$pos, $user ? $user['mobile'] : '未知');
  825. $objPHPExcel->getActiveSheet()->setCellValue("D".$pos, $user ? $user['trueName'] : '未知');
  826. $objPHPExcel->getActiveSheet()->setCellValue("E".$pos, $model['title']);
  827. $objPHPExcel->getActiveSheet()->setCellValue("F".$pos, $item['moneySubject'] + $item['interest']);
  828. $objPHPExcel->getActiveSheet()->setCellValue("G".$pos, $model['repayTime']);
  829. $objPHPExcel->getActiveSheet()->setCellValue("H".$pos, $item['moneySubject']);
  830. $objPHPExcel->getActiveSheet()->setCellValue("I".$pos, $item['money']);
  831. $objPHPExcel->getActiveSheet()->setCellValue("J".$pos, $item['interest']);
  832. $objPHPExcel->getActiveSheet()->setCellValue("K".$pos, $hongbaoMoney);
  833. $objPHPExcel->getActiveSheet()->setCellValue("L".$pos, $item['year'] + $item['yearSystem'] + $jiaxi);
  834. $objPHPExcel->getActiveSheet()->setCellValue("M".$pos, $jiaxi);
  835. $objPHPExcel->getActiveSheet()->setCellValue("N".$pos, $item['addTime']);
  836. $objPHPExcel->getActiveSheet()->setCellValue("O".$pos, $item['investDay']);
  837. $objPHPExcel->getActiveSheet()->setCellValue("P".$pos, $item['statusText']);
  838. $objPHPExcel->getActiveSheet()->setCellValue("Q".$pos, ' '.$user['userBank']['bankNumber']);
  839. $objPHPExcel->getActiveSheet()->getStyle("Q".$pos)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
  840. $objPHPExcel->getActiveSheet()->setCellValue("R".$pos, $user['userBank']['bank']['bankName']);
  841. $pos += 1;
  842. }
  843. ob_end_clean();
  844. header("Content-Type: application/vnd.ms-excel");
  845. header('Content-Disposition: attachment;filename="'.$model['title'].'xls"');
  846. header('Cache-Control: max-age=0');
  847. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  848. //$objWriter->save('php://output');
  849. $filename = Common::timetodate($model->getData('overTime'), 0).'到期_'.$model['title'].'.xls';
  850. $safeDiv = 'excel/'.md5(THINK_START_TIME);
  851. $package = ROOT_PATH.'public/'.$safeDiv;
  852. $fullname = $package.'/'.$filename;
  853. mkdir ($package,0777,true);
  854. $objWriter->save($fullname);
  855. return Common::rm(1, '操作成功', [
  856. 'fileUrl'=>request()->domain().'/'.$safeDiv.'/'.$filename
  857. ]);
  858. }
  859. private function getItem($map = []) {
  860. $map['subjectID'] = $this->app['subjectID'];
  861. $item= Model::with('subjectType,interestType,interestTimeType,subjectStat')->where($map)->find();
  862. if(!$item) {
  863. return false;
  864. }
  865. $item->append(['statusText','repayTime'])->hidden(['subjectID','subjectTypeID','interestTypeID','interestTimeTypeID',
  866. 'subjectStat'=>[
  867. 'subjectID','subjectStatID'
  868. ]
  869. ]);
  870. return $item;
  871. }
  872. public function init() {
  873. User::destroy([
  874. 'watchID'=>$this->app['watchID']
  875. ]);
  876. return Common::rm(1, '操作成功');
  877. }
  878. public function getUserByWatchID()
  879. {
  880. $model = User::get([
  881. 'watchID'=>$this->app['watchID']
  882. ]);
  883. if(!$model) {
  884. return Common::rm(-1, '不存在');
  885. }
  886. $model->append([
  887. 'userID'
  888. ])->visible([
  889. 'status',
  890. 'height',
  891. 'weight',
  892. 'gender',
  893. 'trueName'
  894. ]);
  895. return Common::rm(1, '操作成功', [
  896. 'user'=>$model
  897. ]);
  898. }
  899. }