Loan.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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\Loan as Model;
  10. use tool\Common;
  11. class Loan extends Base
  12. {
  13. /**
  14. * @api {post} loan/update 新增/更新loan统一接口
  15. * @apiVersion 1.0.0
  16. * @apiName update
  17. * @apiDescription 新增/更新loan统一接口
  18. * @apiGroup Loan
  19. *
  20. * @apiParam {Number} activeID 类型ID,更新时为必传字段,新增时保持bannerID必须为0
  21. * @apiParam {String} thumbPc pc图片url
  22. * @apiParam {String} thumbApp app图片Url
  23. * @apiParam {String} linkPc 图片url
  24. * @apiParam {String} linkApp 图片url
  25. * @apiParam {String} title 标题
  26. * @apiParam {String} note 备注
  27. * @apiParam {String} {isOnLinePc=0,1} pc是否在线上,0-线下,1线上
  28. * @apiParam {String} {isOnLineApp=0,1} app是否在线上,0-线下,1线上
  29. * @apiParamExample {json} 发送报文:
  30. {
  31. "activeID": 2,
  32. "thumbPc": "http://www.baidu.com/image.jpg",
  33. "thumbApp": "http://www.baidu.com/",
  34. "linkPc": "http://www.baidu.com/image.jpg",
  35. "linkApp": "http://www.baidu.com/",
  36. "title": "春旗佳节游泳包",
  37. "note": "春旗佳节游泳包撒的发生的发生大法师打发斯蒂芬",
  38. "isOnLinePc": 0,
  39. "isOnLineApp": 1
  40. }
  41. *
  42. * @apiSuccess {Number} bannerID bannerID
  43. * @apiSuccessExample {json} 返回json数据(举例):
  44. {
  45. "code": 1,
  46. "msg": "操作成功",
  47. "content": {
  48. "activeID": 12
  49. }
  50. }
  51. * @apiUse CreateUserError
  52. */
  53. public function update()
  54. {
  55. if(!isset($this->app['loanID']) ||!$this->app['loanID']) {
  56. $model = Model::create([
  57. 'mobile' => $this->app['mobile'],
  58. 'name' => $this->app['name'],
  59. 'money' => $this->app['money'],
  60. 'year' => $this->app['year'],
  61. 'certType'=> $this->app['certType'],
  62. 'certContent' => $this->app['certContent'],
  63. 'pledge' => $this->app['pledge'],
  64. 'financingEntity' => $this->app['financingEntity'],
  65. 'usage' => $this->app['usage'],
  66. 'status' => Model::STATUS_OK,
  67. 'imageUrl' => $this->app['imageUrl'],
  68. 'contractImageUrl' => $this->app['contractImageUrl'],
  69. 'info' => $this->app['info'],
  70. 'pledgeType'=>$this->app['pledgeType'],
  71. ]);
  72. }
  73. else {
  74. $model = Model::update([
  75. 'mobile' => $this->app['mobile'],
  76. 'name' => $this->app['name'],
  77. 'money' => $this->app['money'],
  78. 'year' => $this->app['year'],
  79. 'certType'=> $this->app['certType'],
  80. 'certContent' => $this->app['certContent'],
  81. 'pledge' => $this->app['pledge'],
  82. 'financingEntity' => $this->app['financingEntity'],
  83. 'usage' => $this->app['usage'],
  84. 'imageUrl' => $this->app['imageUrl'],
  85. 'contractImageUrl' => $this->app['contractImageUrl'],
  86. 'info' => $this->app['info'],
  87. 'pledgeType'=>$this->app['pledgeType']
  88. ], [
  89. 'loanID'=>$this->app['loanID']
  90. ]);
  91. $model['loanID'] = $this->app['loanID'];
  92. }
  93. return Common::rm(1, '操作成功', [
  94. 'loanID'=>$model['loanID']
  95. ]);
  96. }
  97. public function getLoanList() {
  98. $map = [];
  99. if( isset($this->app['addTimeTo']) && $this->app['addTimeTo'] &&
  100. isset($this->app['addTimeFrom']) && $this->app['addTimeTo']) {
  101. $map['addTime'] = ['between time', [$this->app['addTimeFrom'],$this->app['addTimeTo']]];
  102. }
  103. if(isset($this->app['keyword']) && $this->app['keyword']) {
  104. $map['mobile|certContent|name|money'] = ['like', '%'.$this->app['keyword'].'%'];
  105. }
  106. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  107. $this->app['pageIndex'] = 1;
  108. }
  109. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  110. $this->app['pageItemCount'] = 10;
  111. }
  112. $count = Model::where($map)->count();
  113. $list = Model::where($map)->order('addTime desc')->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
  114. if($list->isEmpty()) {
  115. return Common::rm(1, '操作成功', [
  116. 'loanList'=>[],
  117. 'count'=>0,
  118. 'pageItemCount'=>$this->app['pageItemCount']
  119. ]);
  120. }
  121. return Common::rm(1, '操作成功', [
  122. 'loanList'=>$list,
  123. 'count'=>$count,
  124. 'pageItemCount'=>$this->app['pageItemCount'],
  125. ]);
  126. }
  127. public function getDetail() {
  128. $item = Model::get($this->app['loanID']);
  129. if(!$item) {
  130. return Common::rm(-32, '没有数据');
  131. }
  132. return Common::rm(1, '操作成功', [
  133. 'detail'=>$item
  134. ]);
  135. }
  136. public function actionDelete() {
  137. $model = Model::get($this->app['loanID']);
  138. $model->delete();
  139. return Common::rm(1, '操作成功');
  140. }
  141. }