作者 杨育虎
1 个管道 的构建 通过 耗费 1 秒

Merge branch 'master' of http://114.215.101.231:8099/guosheng/community

Conflicts:
	public/api.html
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\controller;
  5 +
  6 +use app\api\model\Deposit;
  7 +use app\api\model\DepositOrder;
  8 +use app\api\model\Industry;
  9 +use app\api\model\StoreComment;
  10 +use app\api\model\StoreInform;
  11 +use app\api\model\StoreInformGood;
  12 +use app\api\model\UserHouse;
  13 +use app\api\validate\HotValidate;
  14 +use app\common\controller\Api;
  15 +use think\Db;
  16 +use think\Exception;
  17 +use think\exception\PDOException;
  18 +use think\Request;
  19 +
  20 +/**
  21 + * 周边热点接口
  22 + */
  23 +class Hot extends Api
  24 +{
  25 + protected $noNeedLogin = [];
  26 + protected $noNeedRight = ['*'];
  27 + protected $store_model;
  28 + protected $store_inform_model;
  29 + protected $store_inform_good_model;
  30 + protected $user_house_model;
  31 + protected $industry_model;
  32 + protected $favorite_model;
  33 + protected $comment_model;
  34 + protected $good_model;
  35 + protected $follow_model;
  36 + protected $user_id;
  37 +
  38 + public function __construct(Request $request,\app\api\model\Store $store,Industry $industry,StoreInform $store_inform,UserHouse $user_house,StoreInformGood $store_inform_good)
  39 + {
  40 + parent::__construct($request);
  41 + $this->industry_model = $industry;
  42 + $this->store_model = $store;
  43 + $this->store_inform_model = $store_inform;
  44 + $this->store_inform_good_model = $store_inform_good;
  45 + $this->user_house_model = $user_house;
  46 + $this->user_id = $this->auth->id;
  47 + }
  48 +
  49 + /**
  50 + * 商圈信息列表
  51 + * @ApiWeigh (80)
  52 + *
  53 + * @ApiTitle (商圈信息列表)
  54 + * @ApiSummary (商圈信息列表)
  55 + * @ApiMethod (POST)
  56 + * @ApiRoute (/api/hot/store_list)
  57 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  58 + * @ApiParams (name="page", type="integer", required=true, description="页数")
  59 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  60 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  61 + * @ApiReturn ({
  62 + 'code':'1',
  63 + 'msg':'返回成功',
  64 + "data": {
  65 + "list": [
  66 + {
  67 + "id": 1,
  68 + "name": "行业名称",
  69 + "weigh": 0,
  70 + }
  71 + ]
  72 + }
  73 + })
  74 + */
  75 + public function store_list()
  76 + {
  77 + if($this->request->isPost()){
  78 + $page = $this->request->param('page',1,'intval');
  79 + $house_ids = $this->user_house_model->where('user_id',$this->user_id)->column('house_id');
  80 + $query = function ($query) use ($house_ids){
  81 + foreach ($house_ids as $k=>$v){
  82 + $w = ['house_ids'=>['like','%,'.$v.',%']];
  83 + if($k == 0) {
  84 + $query->where($w);
  85 + } else {
  86 + $query->whereOr($w);
  87 + }
  88 + }
  89 + };
  90 + $where = [
  91 + 'where' => $query
  92 + ];
  93 + $order = ['number'=>'DESC','createtime'=>'DESC'];
  94 + $inform = $this->store_inform_model->pageSelect($page,$where,'*',$order,config('option.num'));
  95 + $list = $inform->items();
  96 + foreach ($list as &$v) {
  97 + // 获取点赞数及是否点赞
  98 + $where_g = [
  99 + 'object_id' => $v['id']
  100 + ];
  101 + $v['good_count'] = $this->store_inform_good_model->getCount($where_g);
  102 + $where_g['user_id'] = $this->user_id;
  103 + $v['is_good'] = $this->store_inform_good_model->getCount($where_g);
  104 + }
  105 + $return = [
  106 + 'list' => $list,
  107 + 'this_page' => $inform->currentPage(),
  108 + 'total_page' => $inform->lastPage()
  109 + ];
  110 + $this->success('请求成功',$return);
  111 + }
  112 + }
  113 +
  114 + /**
  115 + * 留言提交
  116 + * @ApiWeigh (50)
  117 + *
  118 + * @ApiTitle (留言提交)
  119 + * @ApiSummary (留言提交)
  120 + * @ApiMethod (POST)
  121 + * @ApiRoute (/api/hot/comment_add)
  122 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  123 + * @ApiParams (name="store_id", type="integer", required=true, description="店铺id")
  124 + * @ApiParams (name="content", type="string", required=true, description="留言内容")
  125 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  126 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  127 + * @ApiReturn ({
  128 + 'code':'1',
  129 + 'msg':'返回成功'
  130 + })
  131 + */
  132 + public function comment_add()
  133 + {
  134 + $param = (new HotValidate())->goCheck('comment_add');
  135 + $where = [
  136 + 'where' => ['id' => $param['store_id']]
  137 + ];
  138 + $store = $this->store_model->findOrFail($where);
  139 + Db::startTrans();
  140 + $result = false;
  141 + try{
  142 + $param['user_id'] = $this->auth->id;
  143 + $param['store_user_id'] = $store['user_id'];
  144 + $model = new StoreComment();
  145 + $result = $model->add($param);
  146 + Db::commit();
  147 + } catch (PDOException $e) {
  148 + Db::rollback();
  149 + $this->error($e->getMessage());
  150 + } catch (Exception $e) {
  151 + Db::rollback();
  152 + $this->error($e->getMessage());
  153 + }
  154 + if(!$result) {
  155 + $this->error('留言失败');
  156 + }
  157 + $this->success('留言成功');
  158 + }
  159 +}
@@ -4,12 +4,18 @@ @@ -4,12 +4,18 @@
4 namespace app\api\controller; 4 namespace app\api\controller;
5 5
6 use addons\litestore\model\Litestoreorder; 6 use addons\litestore\model\Litestoreorder;
  7 +use app\api\model\Deposit;
  8 +use app\api\model\DepositOrder;
7 use app\api\model\Industry; 9 use app\api\model\Industry;
8 use app\api\model\LitestoreBanner; 10 use app\api\model\LitestoreBanner;
9 use app\api\model\LitestoreGoodsSpec; 11 use app\api\model\LitestoreGoodsSpec;
10 use app\api\model\Report; 12 use app\api\model\Report;
11 use app\api\model\StoreApply; 13 use app\api\model\StoreApply;
  14 +use app\api\model\StoreComment;
  15 +use app\api\model\StoreInform;
  16 +use app\api\model\StoreOrder;
12 use app\api\model\UserSearch; 17 use app\api\model\UserSearch;
  18 +use app\api\validate\StoreValidate;
13 use app\common\controller\Api; 19 use app\common\controller\Api;
14 use EasyWeChat\Foundation\Application; 20 use EasyWeChat\Foundation\Application;
15 use EasyWeChat\Payment\Order; 21 use EasyWeChat\Payment\Order;
@@ -28,24 +34,20 @@ class Store extends Api @@ -28,24 +34,20 @@ class Store extends Api
28 protected $noNeedRight = ['*']; 34 protected $noNeedRight = ['*'];
29 protected $store_model; 35 protected $store_model;
30 protected $industry_model; 36 protected $industry_model;
31 - protected $goods_model;  
32 - protected $banner_model;  
33 - protected $spec_model;  
34 - protected $search_model; 37 + protected $deposit_model;
  38 + protected $deposit_order_model;
35 protected $favorite_model; 39 protected $favorite_model;
36 protected $comment_model; 40 protected $comment_model;
37 protected $good_model; 41 protected $good_model;
38 protected $follow_model; 42 protected $follow_model;
39 protected $user_id; 43 protected $user_id;
40 44
41 - public function __construct(Request $request, LitestoreBanner $banner, \app\api\model\LitestoreGoods $goods,LitestoreGoodsSpec $spec,UserSearch $search,\app\api\model\Store $store,Industry $industry) 45 + public function __construct(Request $request,\app\api\model\Store $store,Industry $industry,Deposit $deposit,DepositOrder $deposit_order)
42 { 46 {
43 parent::__construct($request); 47 parent::__construct($request);
44 - $this->banner_model = $banner;  
45 $this->industry_model = $industry; 48 $this->industry_model = $industry;
46 - $this->goods_model = $goods;  
47 - $this->spec_model = $spec;  
48 - $this->search_model = $search; 49 + $this->deposit_model = $deposit;
  50 + $this->deposit_order_model = $deposit_order;
49 $this->store_model = $store; 51 $this->store_model = $store;
50 $this->user_id = $this->auth->id; 52 $this->user_id = $this->auth->id;
51 } 53 }
@@ -96,7 +98,7 @@ class Store extends Api @@ -96,7 +98,7 @@ class Store extends Api
96 98
97 /** 99 /**
98 * 店铺申请 100 * 店铺申请
99 - * @ApiWeigh (77) 101 + * @ApiWeigh (55)
100 * 102 *
101 * @ApiTitle (店铺申请) 103 * @ApiTitle (店铺申请)
102 * @ApiSummary (店铺申请) 104 * @ApiSummary (店铺申请)
@@ -118,7 +120,7 @@ class Store extends Api @@ -118,7 +120,7 @@ class Store extends Api
118 */ 120 */
119 public function store_add() 121 public function store_add()
120 { 122 {
121 -// $param = (new RecruitValidate())->goCheck('add'); 123 + $param = (new StoreValidate())->goCheck('store_add');
122 $order_sn = $param['order_sn'] = get_order_sn(); 124 $order_sn = $param['order_sn'] = get_order_sn();
123 $pay_data = []; 125 $pay_data = [];
124 if($this->auth->end_time > time()) { 126 if($this->auth->end_time > time()) {
@@ -170,7 +172,7 @@ class Store extends Api @@ -170,7 +172,7 @@ class Store extends Api
170 172
171 /** 173 /**
172 * 开通社区提交 174 * 开通社区提交
173 - * @ApiWeigh (74) 175 + * @ApiWeigh (50)
174 * 176 *
175 * @ApiTitle (开通社区提交) 177 * @ApiTitle (开通社区提交)
176 * @ApiSummary (开通社区提交) 178 * @ApiSummary (开通社区提交)
@@ -192,14 +194,13 @@ class Store extends Api @@ -192,14 +194,13 @@ class Store extends Api
192 */ 194 */
193 public function store_apply() 195 public function store_apply()
194 { 196 {
195 -// $param = (new RecruitValidate())->goCheck('add'); 197 + $param = (new StoreValidate())->goCheck('store_apply');
196 Db::startTrans(); 198 Db::startTrans();
197 $result = false; 199 $result = false;
198 try{ 200 try{
199 $param['user_id'] = $this->auth->id; 201 $param['user_id'] = $this->auth->id;
200 $model = new StoreApply(); 202 $model = new StoreApply();
201 $result = $model->add($param); 203 $result = $model->add($param);
202 - $id = $model->id;  
203 Db::commit(); 204 Db::commit();
204 } catch (PDOException $e) { 205 } catch (PDOException $e) {
205 Db::rollback(); 206 Db::rollback();
@@ -216,7 +217,7 @@ class Store extends Api @@ -216,7 +217,7 @@ class Store extends Api
216 217
217 /** 218 /**
218 * 举报建议提交 219 * 举报建议提交
219 - * @ApiWeigh (70) 220 + * @ApiWeigh (45)
220 * 221 *
221 * @ApiTitle (举报建议提交) 222 * @ApiTitle (举报建议提交)
222 * @ApiSummary (举报建议提交) 223 * @ApiSummary (举报建议提交)
@@ -233,7 +234,7 @@ class Store extends Api @@ -233,7 +234,7 @@ class Store extends Api
233 */ 234 */
234 public function store_report() 235 public function store_report()
235 { 236 {
236 -// $param = (new RecruitValidate())->goCheck('add'); 237 + $param = (new StoreValidate())->goCheck('store_report');
237 Db::startTrans(); 238 Db::startTrans();
238 $result = false; 239 $result = false;
239 try{ 240 try{
@@ -254,4 +255,441 @@ class Store extends Api @@ -254,4 +255,441 @@ class Store extends Api
254 } 255 }
255 $this->success('提交成功'); 256 $this->success('提交成功');
256 } 257 }
  258 +
  259 + /**
  260 + * 商家首页
  261 + * @ApiWeigh (40)
  262 + *
  263 + * @ApiTitle (商家首页)
  264 + * @ApiSummary (商家首页)
  265 + * @ApiMethod (POST)
  266 + * @ApiRoute (/api/store/store)
  267 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  268 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  269 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  270 + * @ApiReturn ({
  271 + 'code':'1',
  272 + 'msg':'返回成功'
  273 + })
  274 + */
  275 + public function store()
  276 + {
  277 + $store = $this->get_store();
  278 + $return = [
  279 + 'id' => $store['id'],
  280 + 'store_name' => $store['store_name'],
  281 + 'image_arr' => $store['image_arr'],
  282 + ];
  283 + $this->success('成功',$return);
  284 + }
  285 +
  286 + /**
  287 + * 店铺信息更新
  288 + * @ApiWeigh (35)
  289 + *
  290 + * @ApiTitle (店铺信息更新)
  291 + * @ApiSummary (店铺信息更新)
  292 + * @ApiMethod (POST)
  293 + * @ApiRoute (/api/store/store_edit)
  294 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  295 + * @ApiParams (name="id", type="integer", required=true, description="店铺id")
  296 + * @ApiParams (name="store_icon", type="string", required=true, description="店铺图标")
  297 + * @ApiParams (name="store_name", type="string", required=true, description="店铺名称")
  298 + * @ApiParams (name="mobile", type="string", required=true, description="商家电话")
  299 + * @ApiParams (name="province", type="string", required=true, description="省")
  300 + * @ApiParams (name="city", type="string", required=true, description="市")
  301 + * @ApiParams (name="region", type="string", required=true, description="区")
  302 + * @ApiParams (name="images", type="string", required=true, description="宣传图/轮播图")
  303 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  304 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  305 + * @ApiReturn ({
  306 + 'code':'1',
  307 + 'msg':'返回成功'
  308 + })
  309 + */
  310 + public function store_edit()
  311 + {
  312 + $param = (new StoreValidate())->goCheck('store_edit');
  313 + $store = $this->get_store($param['id']);
  314 + Db::startTrans();
  315 + $result = false;
  316 + try{
  317 + $param['user_id'] = $this->auth->id;
  318 + $result = $this->store_model->edit($param);
  319 + Db::commit();
  320 + } catch (PDOException $e) {
  321 + Db::rollback();
  322 + $this->error($e->getMessage());
  323 + } catch (Exception $e) {
  324 + Db::rollback();
  325 + $this->error($e->getMessage());
  326 + }
  327 + if(!$result) {
  328 + $this->error('保存失败');
  329 + }
  330 + $this->success('保存成功');
  331 + }
  332 +
  333 + /**
  334 + * 发布信息
  335 + * @ApiWeigh (30)
  336 + *
  337 + * @ApiTitle (发布信息)
  338 + * @ApiSummary (发布信息)
  339 + * @ApiMethod (POST)
  340 + * @ApiRoute (/api/store/store_inform_add)
  341 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  342 + * @ApiParams (name="content", type="string", required=true, description="详细内容")
  343 + * @ApiParams (name="images", type="string", required=true, description="图片")
  344 + * @ApiParams (name="house_ids", type="string", required=true, description="推广社区")
  345 + * @ApiParams (name="type", type="integer", required=true, description="推广类型1=红包推送信息2=一般信息")
  346 + * @ApiParams (name="red_package", type="string", required=false, description="红包总金额")
  347 + * @ApiParams (name="number", type="string", required=false, description="红包数量")
  348 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  349 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  350 + * @ApiReturn ({
  351 + 'code':'1',
  352 + 'msg':'返回成功'
  353 + })
  354 + */
  355 + public function store_inform_add()
  356 + {
  357 + $param = (new StoreValidate())->goCheck('store_inform_add');
  358 + if($param['type'] == 1) {
  359 + $param = (new StoreValidate())->goCheck('red');
  360 + }
  361 + $store = $this->get_store();
  362 + if($param['type'] == 1) {
  363 + $param['score'] = bcadd(config('site.send_score'),$param['red_package'],2);
  364 + }
  365 + Db::startTrans();
  366 + $result = false;
  367 + try{
  368 + $param['user_id'] = $this->auth->id;
  369 + $param['house_ids'] = ','.$param['house_ids'].',';
  370 + $model = new StoreInform();
  371 + $result = $model->add($param);
  372 + Db::commit();
  373 + } catch (PDOException $e) {
  374 + Db::rollback();
  375 + $this->error($e->getMessage());
  376 + } catch (Exception $e) {
  377 + Db::rollback();
  378 + $this->error($e->getMessage());
  379 + }
  380 + if(!$result) {
  381 + $this->error('提交失败');
  382 + }
  383 + $this->success('提交成功');
  384 + }
  385 +
  386 + /**
  387 + * 绑定新社区
  388 + * @ApiWeigh (25)
  389 + *
  390 + * @ApiTitle (绑定新社区)
  391 + * @ApiSummary (绑定新社区)
  392 + * @ApiMethod (POST)
  393 + * @ApiRoute (/api/store/store_new)
  394 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  395 + * @ApiParams (name="house_ids", type="string", sample="店铺1id,店铺2id", required=true, description="绑定社区id")
  396 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  397 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  398 + * @ApiReturn ({
  399 + 'code':'1',
  400 + 'msg':'返回成功'
  401 + })
  402 + */
  403 + public function store_new()
  404 + {
  405 + $param = (new StoreValidate())->goCheck('store_new');
  406 + $store = $this->get_store();
  407 + $order_sn = $param['order_sn'] = get_order_sn();
  408 + $pay_data = [];
  409 + if($this->auth->end_time > time()) {
  410 + $param['status'] = 2;
  411 + } else {
  412 + $param['status'] = 1;
  413 + // 获取小程序配置
  414 + $options = \config('miniprogram.basic');
  415 + $app = new Application($options);
  416 + $payment = $app->payment;
  417 + // 获取支付参数
  418 + $attributes = [
  419 + 'body' => '发布招募合伙人',
  420 + 'out_trade_no' => $order_sn,
  421 + 'total_fee' => 1, // $param['money'] * 100
  422 + 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
  423 + 'notify_url' => url('index/ajax/notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  424 + 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  425 + 'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),
  426 + ];
  427 + $order = new Order($attributes);
  428 + $order_result = $payment->pay($order);
  429 + if($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {
  430 + $prepayId = $order_result->prepay_id;
  431 + } else {
  432 + $this->error($order_result['return_msg']);
  433 + }
  434 + }
  435 + $model = new StoreOrder();
  436 + Db::startTrans();
  437 + $result = false;
  438 + $result_invite = true;
  439 + try{
  440 + $param['store_id'] = $store['id'];
  441 + $param['user_id'] = $this->auth->id;
  442 + $result = $model->add($param);
  443 + $id = $model->id;
  444 + Db::commit();
  445 + } catch (PDOException $e) {
  446 + Db::rollback();
  447 + $this->error($e->getMessage());
  448 + } catch (Exception $e) {
  449 + Db::rollback();
  450 + $this->error($e->getMessage());
  451 + }
  452 + if(!$result || !$result_invite) {
  453 + $this->error('提交失败');
  454 + }
  455 + $this->success('提交成功',['id'=>$id,'status'=>$param['status'],'pay_data'=>$pay_data]);
  456 + }
  457 +
  458 + /**
  459 + * 留言消息
  460 + * @ApiWeigh (80)
  461 + *
  462 + * @ApiTitle (留言消息)
  463 + * @ApiSummary (留言消息)
  464 + * @ApiMethod (POST)
  465 + * @ApiRoute (/api/store/comment_list)
  466 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  467 + * @ApiParams (name="page", type="integer", required=true, description="页数")
  468 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  469 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  470 + * @ApiReturn ({
  471 + 'code':'1',
  472 + 'msg':'返回成功',
  473 + "data": {
  474 + "list": [
  475 + {
  476 + "id": 1,
  477 + "name": "行业名称",
  478 + "weigh": 0,
  479 + }
  480 + ]
  481 + }
  482 + })
  483 + */
  484 + public function store_list()
  485 + {
  486 + if($this->request->isPost()){
  487 + $param = (new StoreValidate())->goCheck('comment_reply');
  488 + $store = $this->get_store();
  489 + $page = $param['page'];
  490 + $where = [
  491 + 'where' => ['store_id'=>$store['id']],
  492 + 'with' => ['user_info']
  493 + ];
  494 + $order = ['number'=>'DESC','createtime'=>'DESC'];
  495 + $model = new StoreComment();
  496 + $comment = $model->pageSelect($page,$where,'*',$order,config('option.num'));
  497 + $list = $comment->items();
  498 + $return = [
  499 + 'list' => $list,
  500 + 'this_page' => $comment->currentPage(),
  501 + 'total_page' => $comment->lastPage()
  502 + ];
  503 + $this->success('请求成功',$return);
  504 + }
  505 + }
  506 +
  507 + /**
  508 + * 留言消息
  509 + * @ApiWeigh (50)
  510 + *
  511 + * @ApiTitle (留言消息)
  512 + * @ApiSummary (留言消息)
  513 + * @ApiMethod (POST)
  514 + * @ApiRoute (/api/store/comment_reply)
  515 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  516 + * @ApiParams (name="comment_id", type="integer", required=true, description="留言id")
  517 + * @ApiParams (name="content", type="string", required=true, description="留言内容")
  518 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  519 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  520 + * @ApiReturn ({
  521 + 'code':'1',
  522 + 'msg':'返回成功'
  523 + })
  524 + */
  525 + public function comment_reply()
  526 + {
  527 + $param = (new StoreValidate())->goCheck('comment_reply');
  528 + Db::startTrans();
  529 + $result = false;
  530 + try{
  531 + $param['user_id'] = $this->auth->id;
  532 + $model = new StoreComment();
  533 + $result = $model->add($param);
  534 + Db::commit();
  535 + } catch (PDOException $e) {
  536 + Db::rollback();
  537 + $this->error($e->getMessage());
  538 + } catch (Exception $e) {
  539 + Db::rollback();
  540 + $this->error($e->getMessage());
  541 + }
  542 + if(!$result) {
  543 + $this->error('提交失败');
  544 + }
  545 + $this->success('提交成功');
  546 + }
  547 +
  548 + /**
  549 + * 板币充值列表
  550 + * @ApiWeigh (20)
  551 + *
  552 + * @ApiTitle (板币充值列表)
  553 + * @ApiSummary (板币充值列表)
  554 + * @ApiMethod (POST)
  555 + * @ApiRoute (/api/store/deposit)
  556 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  557 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  558 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  559 + * @ApiReturn ({
  560 + 'code':'1',
  561 + 'msg':'返回成功',
  562 + "data": {
  563 + "list": [
  564 + {
  565 + "id": 1,
  566 + "name": "行业名称",
  567 + "weigh": 0,
  568 + }
  569 + ]
  570 + }
  571 + })
  572 + */
  573 + public function deposit()
  574 + {
  575 + if($this->request->isPost()){
  576 + $keyword = $this->request->param('keyword','');
  577 + $where = [
  578 + 'where' => []
  579 + ];
  580 + if($keyword) {
  581 + $where['where'] = ['name'=>['like','%'.$keyword.'%']];
  582 + }
  583 + $indus = $this->industry_model->selectOrFail($where,false,'*','weigh');
  584 + $return = [
  585 + 'list' => $indus,
  586 + ];
  587 + $this->success('请求成功',$return);
  588 + }
  589 + }
  590 +
  591 + /**
  592 + * 板币充值提交
  593 + * @ApiWeigh (15)
  594 + *
  595 + * @ApiTitle (板币充值提交)
  596 + * @ApiSummary (板币充值提交)
  597 + * @ApiMethod (POST)
  598 + * @ApiRoute (/api/store/deposit_order)
  599 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  600 + * @ApiParams (name="deposit_id", type="integer", required=true, description="板币充值id")
  601 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  602 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  603 + * @ApiReturn ({
  604 + 'code':'1',
  605 + 'msg':'返回成功'
  606 + })
  607 + */
  608 + public function deposit_order()
  609 + {
  610 + $param = (new StoreValidate())->goCheck('deposit_order');
  611 + $store = $this->get_store();
  612 + $deposit = $this->deposit_model->findOrFail(['id'=>$param['depost_id']]);
  613 + $order_sn = $param['order_sn'] = get_order_sn();
  614 + $pay_data = [];
  615 + if($this->auth->end_time > time()) {
  616 + $param['status'] = 2;
  617 + } else {
  618 + $param['status'] = 1;
  619 + // 获取小程序配置
  620 + $options = \config('miniprogram.basic');
  621 + $app = new Application($options);
  622 + $payment = $app->payment;
  623 + // 获取支付参数
  624 + $attributes = [
  625 + 'body' => '板币充值',
  626 + 'out_trade_no' => $order_sn,
  627 + 'total_fee' => 1, // $param['money'] * 100
  628 + 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
  629 + 'notify_url' => url('index/ajax/notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  630 + 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  631 + 'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),
  632 + ];
  633 + $order = new Order($attributes);
  634 + $order_result = $payment->pay($order);
  635 + if($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {
  636 + $prepayId = $order_result->prepay_id;
  637 + } else {
  638 + $this->error($order_result['return_msg']);
  639 + }
  640 + }
  641 + $model = $this->deposit_order_model;
  642 + Db::startTrans();
  643 + $result = false;
  644 + $result_invite = true;
  645 + try{
  646 + $param['deposit_id'] = $store['id'];
  647 + $param['user_id'] = $this->auth->id;
  648 + $param['score'] = $deposit['score'];
  649 + $param['money'] = $deposit['money'];
  650 + $result = $model->add($param);
  651 + $id = $model->id;
  652 + Db::commit();
  653 + } catch (PDOException $e) {
  654 + Db::rollback();
  655 + $this->error($e->getMessage());
  656 + } catch (Exception $e) {
  657 + Db::rollback();
  658 + $this->error($e->getMessage());
  659 + }
  660 + if(!$result || !$result_invite) {
  661 + $this->error('提交失败');
  662 + }
  663 + $this->success('提交成功',['id'=>$id,'status'=>$param['status'],'pay_data'=>$pay_data]);
  664 + }
  665 +
  666 + /**
  667 + * 获取店铺信息
  668 + * @param string $id 店铺id
  669 + */
  670 + private function get_store($id = null)
  671 + {
  672 + $where_s = ['user_id'=>$this->user_id];
  673 + if($id) {
  674 + $where_s['id'] = $id;
  675 + }
  676 + $where = [
  677 + 'where' => $where_s,
  678 + 'with' => ['user_info']
  679 + ];
  680 + $store = $this->store_model->findOrFail($where,false);
  681 + if(!$store) {
  682 + $this->error('请先提交商家入驻申请');
  683 + }
  684 + if($store['status'] == 4) {
  685 + $this->error('请先提交商家入驻申请');
  686 + }
  687 + if($store['status'] == 1) {
  688 + $this->error('未提交入驻申请');
  689 + }
  690 + if($store['status'] == 2) {
  691 + $this->error('商家申请仍在审核中');
  692 + }
  693 + return $store;
  694 + }
257 } 695 }
@@ -44,6 +44,13 @@ class Base extends Model { @@ -44,6 +44,13 @@ class Base extends Model {
44 } 44 }
45 45
46 /** 46 /**
  47 + * 构造关联社区文章查询
  48 + */
  49 + public function store(){
  50 + return $this->hasOne("Store","sort_id","id")->field("id,store_name,store_icon,industry_id");
  51 + }
  52 +
  53 + /**
47 * 单条查询 54 * 单条查询
48 * @param array $where 查询条件 55 * @param array $where 查询条件
49 * @param string $field 查询field 56 * @param string $field 查询field
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class Deposit extends Base
  8 +{
  9 +
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class DepositOrder extends Base
  8 +{
  9 +
  10 +}
@@ -7,4 +7,19 @@ namespace app\api\model; @@ -7,4 +7,19 @@ namespace app\api\model;
7 class Store extends Base 7 class Store extends Base
8 { 8 {
9 9
  10 + protected $append = [
  11 + 'image_arr'
  12 + ];
  13 +
  14 + public function getImageArrAttr($value,$data)
  15 + {
  16 + $arr = [];
  17 + if($data['images']) {
  18 + $arr = explode(',',$data['images']);
  19 + foreach ($arr as &$v) {
  20 + $v = cdnurl($v);
  21 + }
  22 + }
  23 + return $arr;
  24 + }
10 } 25 }
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class StoreComment extends Base
  8 +{
  9 +
  10 + protected $updateTime = false;
  11 +
  12 + public function getCreatetimeAttr($value)
  13 + {
  14 + return date('Y-m-d H:i:s',$value);
  15 + }
  16 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class StoreInform extends Base
  8 +{
  9 +
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class StoreInformGood extends Base
  8 +{
  9 +
  10 + protected $updateTime = false;
  11 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class StoreOrder extends Base
  8 +{
  9 +
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class UserHouse extends Base
  8 +{
  9 +
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\validate;
  5 +
  6 +
  7 +class HotValidate extends BaseValidate
  8 +{
  9 + protected $rule = [
  10 + 'page' => 'require|integer',
  11 + 'store_id' => 'require',
  12 + 'store_name' => 'require',
  13 + 'mobile' => 'require|regex:^1\d{10}$',
  14 + 'province' => 'require',
  15 + 'city' => 'require',
  16 + 'region' => 'require',
  17 + 'images' => 'require',
  18 + 'content' => 'require',
  19 + 'house_ids' => 'require',
  20 + 'type' => 'require|in:1,2',
  21 + 'red_package' => 'require',
  22 + 'number' => 'require',
  23 + 'deposit_id' => 'require'
  24 + ];
  25 + protected $message = [
  26 + 'page.integer' =>'页数必须是整数',
  27 + 'mobile.regex' =>'手机号格式错误'
  28 + ];
  29 +
  30 + protected $scene = [
  31 + 'common' => ['page'], // 公共分页验证
  32 + 'comment_add' => ['store_id','content'], // 留言提交
  33 + 'store_apply' => ['store_name','province','city','region','name','mobile'], // 开通社区提交
  34 + 'store_report' => ['content'], // 举报建议提交
  35 + 'store_edit' => ['store_icon','store_name','mobile','province','city','region','images'], // 店铺信息修改
  36 + 'store_inform_add' => ['content','images','house_ids','type'], // 发布信息
  37 + 'red' => ['red_package','number'], // 发布信息红包
  38 + 'house_new' => ['house_ids'], // 绑定社区
  39 + 'deposit_order' => ['deposit_id'], // 板币充值提交
  40 + ];
  41 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\validate;
  5 +
  6 +
  7 +class StoreValidate extends BaseValidate
  8 +{
  9 + protected $rule = [
  10 + 'page' => 'require|integer',
  11 + 'store_icon' => 'require',
  12 + 'store_name' => 'require',
  13 + 'mobile' => 'require|regex:^1\d{10}$',
  14 + 'province' => 'require',
  15 + 'city' => 'require',
  16 + 'region' => 'require',
  17 + 'images' => 'require',
  18 + 'content' => 'require',
  19 + 'house_ids' => 'require',
  20 + 'type' => 'require|in:1,2',
  21 + 'red_package' => 'require',
  22 + 'number' => 'require',
  23 + 'deposit_id' => 'require'
  24 + ];
  25 + protected $message = [
  26 + 'page.integer' =>'页数必须是整数',
  27 + 'mobile.regex' =>'手机号格式错误'
  28 + ];
  29 +
  30 + protected $scene = [
  31 + 'common' => ['page'], // 公共分页验证
  32 + 'store_add' => ['store_name','house_ids','industry_id','name','mobile','license'], // 店铺申请
  33 + 'store_apply' => ['store_name','province','city','region','name','mobile'], // 开通社区提交
  34 + 'store_report' => ['content'], // 举报建议提交
  35 + 'store_edit' => ['store_icon','store_name','mobile','province','city','region','images'], // 店铺信息修改
  36 + 'store_inform_add' => ['content','images','house_ids','type'], // 发布信息
  37 + 'red' => ['red_package','number'], // 发布信息红包
  38 + 'house_new' => ['house_ids'], // 绑定社区
  39 + 'comment_reply' => ['comment_id','content'], // 留言回复
  40 + 'deposit_order' => ['deposit_id'], // 板币充值提交
  41 + ];
  42 +}
@@ -37,4 +37,5 @@ return array ( @@ -37,4 +37,5 @@ return array (
37 'mail_from' => '10000@qq.com', 37 'mail_from' => '10000@qq.com',
38 'contact' => '联系我们联系我们022-12345678', 38 'contact' => '联系我们联系我们022-12345678',
39 'settled' => '上架入驻协议', 39 'settled' => '上架入驻协议',
  40 + 'send_score' => '800',
40 ); 41 );
此 diff 太大无法显示。