Subject.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qisse
  5. * Date: 2017/6/27
  6. * Time: 20:02
  7. */
  8. namespace app\mobile\logic;
  9. use app\core\model\Loan;
  10. use app\core\model\Cang;
  11. use app\core\model\Subject as Model;
  12. use tool\Common;
  13. class Subject extends Base
  14. {
  15. public function create()
  16. {
  17. //第一步,得到标的信息
  18. $subject = Subject::get($this->app['subjectID']);
  19. //第二步,新增cang
  20. //1、判断是否过认购期
  21. if(THINK_START_TIME >= $subject['endTime']) {
  22. return Common::rm(-3, '该商品已过认购期,不能购买了');
  23. }
  24. //2、判断是否满标了
  25. if($subject['status'] == Subject::STATUS_FULL) {
  26. return Common::rm(-4, '该商品已经满标,不能购买了');
  27. }
  28. //3、判断是否下架了
  29. if($subject['status'] == Subject::STATUS_OFFLINE) {
  30. return Common::rm(-5, '该商品已经下架,不能购买了');
  31. }
  32. $model = Model::create([
  33. 'subjectID' => $subject['subjectID'],
  34. 'userID' => $this->app['userID'],
  35. 'moneyBuy' => $this->app['moneyBuy'],
  36. 'money' => $this->app['moneyBuy'],
  37. 'status'=>Model::STATUS_UNPAY
  38. ]);
  39. $model['alias'] = Model::createAlias($model['cangID']);
  40. $model->save();
  41. return Common::rm(1, '操作成功', [
  42. 'cangID'=>$model['cangID']
  43. ]);
  44. }
  45. public function createPayParams() {
  46. $this->app = [
  47. 'cangID'=>1
  48. ];
  49. //第一步,获取该仓
  50. $model = Model::get($this->app['cangID']);
  51. if(!$model) {
  52. return Common::rm(-2, '不存在该仓');
  53. }
  54. //第二步,判断仓所属的标的是否过期
  55. $subject = Subject::get($model['subjectID']);
  56. if(!$subject) {
  57. return Common::rm(-12, '不存在该仓所属的标的');
  58. }
  59. //1、判断是否过认购期
  60. if(THINK_START_TIME >= $subject->getData('endTime')) {
  61. return Common::rm(-13, '该商品已过认购期,不能购买了');
  62. }
  63. //2、判断是否满标了
  64. if($subject['status'] == Subject::STATUS_FULL) {
  65. return Common::rm(-14, '该商品已经满标,不能购买了');
  66. }
  67. //3、判断是否下架了
  68. if($subject['status'] == Subject::STATUS_OFFLINE) {
  69. return Common::rm(-15, '该商品已经下架,不能购买了');
  70. }
  71. //第三步,获取支付参数
  72. $pay = new Pay();
  73. $ouerOrder = $pay->createOrder($model['money']);
  74. if(!$ouerOrder) {
  75. return Common::rm(-3, '获取支付参数失败');
  76. }
  77. $model['outerAlias'] = $ouerOrder['outerAlias'];
  78. $model['outerMch'] = $ouerOrder['outerMch'];
  79. $model['outerName'] = $ouerOrder['outerName'];
  80. $model['payTimes'] = $model['payTimes'] + 1;
  81. $model->save();
  82. return Common::rm(1, '操作成功', [
  83. 'cangID'=>$this->app['cangID'],
  84. 'outerAlias'=>$model['outerAlias'],
  85. /*'money'=>$model['money'],*/
  86. 'notify'=>$this->request->domain().'/mobile/notify/cang'
  87. ]);
  88. }
  89. public function getSubjectList() {
  90. $map = [
  91. 'status'=>['in', [Model::STATUS_ONLINE, Model::STATUS_FULL]],
  92. 'isShow'=>1
  93. ];
  94. if(isset($this->app['status']) && $this->app['status']) {
  95. if($this->app['status'] == 1) {
  96. $map['status'] = Model::STATUS_ONLINE;
  97. }
  98. else if($this->app['status'] == 2) {
  99. $map['status'] = ['in', [Model::STATUS_FULL]];
  100. }
  101. else if($this->app['status'] == 3){
  102. $map['status'] = ['in', [Model::STATUS_REPAY]];
  103. }
  104. }
  105. if(isset($this->app['subjectTypeID']) && $this->app['subjectTypeID']) {
  106. $map['subjectTypeID'] = $this->app['subjectTypeID'];
  107. }
  108. if(isset($this->app['term']) && $this->app['term']) {
  109. $map['term'] = $this->app['term'];
  110. }
  111. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  112. $this->app['pageIndex'] = 1;
  113. }
  114. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  115. $this->app['pageItemCount'] = 10;
  116. }
  117. $order = 'status,';
  118. if(isset($this->app['orderTerm']) && $this->app['orderTerm']) {
  119. if($this->app['orderTerm'] == 1) {
  120. $order .= 'term desc,';
  121. }
  122. else {
  123. $order .= 'term,';
  124. }
  125. }
  126. if(isset($this->app['orderYear']) && $this->app['orderYear']) {
  127. if($this->app['orderYear'] == 1) {
  128. $order .= 'year desc,';
  129. }
  130. else {
  131. $order .= 'year,';
  132. }
  133. }
  134. $order .= 'addTime desc';
  135. $this->app['pageItemCount'] = 10;
  136. $count = Model::where($map)->count();
  137. $list = Model::with('subjectType,interestType,interestTimeType,subjectStat')->where($map)->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order($order)->select();
  138. if($list->isEmpty()) {
  139. return Common::rm(-2, '数据为空');
  140. }
  141. $list->append(['statusText','investDay', 'repayTime','reachTime','unit', 'interestBeginTime'])->hidden(['subjectTypeID','beginTime','endTime','multiplePrice','interestTypeID','interestTimeTypeID','isIndexApp','isIndexPc','operation','updateTime',
  142. 'subjectStat'=>[
  143. 'subjectID','subjectStatID'
  144. ]
  145. ])->toArray();
  146. foreach ($list as $k=>$item) {
  147. $list[$k]['contentUrl1'] = $this->h5RootUrl().'/mobile/h5/subjectContent?tab=1' . '&######';
  148. $list[$k]['contentUrl2'] = $this->h5RootUrl().'/mobile/h5/subjectContent?tab=2' . '&######';
  149. $list[$k]['contentUrl3'] = $this->h5RootUrl().'/mobile/h5/subjectContent?tab=3' . '&######';
  150. $list[$k]['subjectType']['icon'] = isset($this->skin['subjectType_icon'][$list[$k]['subjectType']['subjectTypeID']]) ? $this->skin['subjectType_icon'][$list[$k]['subjectType']['subjectTypeID']] : '';
  151. }
  152. return Common::rm(1, '操作成功', [
  153. 'subjectList'=>$list,
  154. 'count'=>$count,
  155. 'pageItemCount'=>$this->app['pageItemCount']
  156. ]);
  157. }
  158. public function getSubjectDetail() {
  159. $item =Model::with('subjectType,interestType,interestTimeType,subjectStat')->where('subjectID', $this->app['subjectID'])->find();
  160. if(!$item) {
  161. return Common::rm(-2, '无数据');
  162. }
  163. $item->append(['statusText','investDay', 'repayTime','reachTime','unit', 'interestBeginTime'])->hidden(['subjectTypeID','beginTime','endTime','multiplePrice','interestTypeID','interestTimeTypeID','isIndexApp','isIndexPc','operation','updateTime',
  164. 'subjectStat'=>[
  165. 'subjectID','subjectStatID'
  166. ]
  167. ])->toArray();
  168. $item['contentUrl1'] = $this->h5RootUrl().'/mobile/h5/subjectContent?tab=1' . '&######';
  169. $item['contentUrl2'] = $this->h5RootUrl().'/mobile/h5/subjectContent?tab=2' . '&######';
  170. $item['contentUrl3'] = $this->h5RootUrl().'/mobile/h5/subjectContent?tab=3' . '&######';
  171. return Common::rm(1, '操作成功', [
  172. 'subjectDetail'=>$item
  173. ]);
  174. }
  175. public function getSubjectContent() {
  176. $list = Cang::with(['user'])->where([
  177. 'subjectID'=>$this->app['subjectID']
  178. ])->order('addTime desc')->select();
  179. $cangList = [];
  180. if(!$list->isEmpty()) {
  181. $cangList = $list->toArray();
  182. }
  183. $subject = Model::get($this->app['subjectID']);
  184. $loan = null;
  185. if($subject) {
  186. $loan = Loan::get($subject['loanID']);
  187. }
  188. return Common::rm(1, '操作成功', [
  189. 'cangList'=>$cangList,
  190. 'loan'=>$loan
  191. ]);
  192. }
  193. public function actionOnline() {
  194. $item = $this->getItem();
  195. if($item['status'] != 1) {
  196. return Common::rm(-3, '不是可以进行的状态,当前状态'.$item['statusText']);
  197. }
  198. $item['status'] = Model::STATUS_ONLINE;
  199. $item->save();
  200. return Common::rm(1, '操作成功', [
  201. 'detail'=>$item
  202. ]);
  203. }
  204. private function getItem($map = []) {
  205. $map['alias'] = $this->app['alias'];
  206. $item= Model::with('subjectType,interestType,interestTimeType,subjectStat')->where($map)->find();
  207. if(!$item) {
  208. return Common::rm(-2, '数据为空');
  209. }
  210. $item->append(['statusText'])->hidden(['subjectID','subjectTypeID','interestTypeID','interestTimeTypeID',
  211. 'subjectStat'=>[
  212. 'subjectID','subjectStatID'
  213. ]
  214. ]);
  215. return $item;
  216. }
  217. }