作者 Cool
1 个管道 的构建 通过 耗费 5 秒

店铺申请接口调试

  1 +<?php
  2 +
  3 +
  4 +namespace app\api\controller;
  5 +
  6 +use addons\litestore\model\Litestoreorder;
  7 +use app\api\model\LitestoreBanner;
  8 +use app\api\model\LitestoreGoodsSpec;
  9 +use app\api\model\UserSearch;
  10 +use app\common\controller\Api;
  11 +use EasyWeChat\Foundation\Application;
  12 +use EasyWeChat\Payment\Order;
  13 +use think\Db;
  14 +use think\Exception;
  15 +use think\exception\PDOException;
  16 +use think\Request;
  17 +
  18 +/**
  19 + * 店铺接口
  20 + */
  21 +class Store extends Api
  22 +{
  23 +
  24 + protected $noNeedLogin = [];
  25 + protected $noNeedRight = ['*'];
  26 + protected $store_model;
  27 + protected $goods_model;
  28 + protected $banner_model;
  29 + protected $spec_model;
  30 + protected $search_model;
  31 + protected $favorite_model;
  32 + protected $comment_model;
  33 + protected $good_model;
  34 + protected $follow_model;
  35 + protected $user_id;
  36 +
  37 + public function __construct(Request $request, LitestoreBanner $banner, \app\api\model\LitestoreGoods $goods,LitestoreGoodsSpec $spec,UserSearch $search,\app\api\model\Store $store)
  38 + {
  39 + parent::__construct($request);
  40 + $this->banner_model = $banner;
  41 + $this->goods_model = $goods;
  42 + $this->spec_model = $spec;
  43 + $this->search_model = $search;
  44 + $this->store_model = $store;
  45 + $this->user_id = $this->auth->id;
  46 + }
  47 +
  48 + /**
  49 + * 店铺申请
  50 + * @ApiWeigh (3)
  51 + *
  52 + * @ApiTitle (店铺申请)
  53 + * @ApiSummary (店铺申请)
  54 + * @ApiMethod (POST)
  55 + * @ApiRoute (/api/store/store_add)
  56 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  57 + * @ApiParams (name="store_name", type="integer", required=true, description="店铺名称")
  58 + * @ApiParams (name="house_ids", type="string", sample="店铺1id,店铺2id", required=true, description="入驻社区")
  59 + * @ApiParams (name="job", type="string", sample="[{'name':'职位名称1','number':'招聘人数1'},{'name':'职位名称2','number':'招聘人数2'}]", required=true, description="招聘职位")
  60 + * @ApiParams (name="industry_id", type="string", required=true, description="行业/关键词id")
  61 + * @ApiParams (name="name", type="string", required=true, description="联系人姓名")
  62 + * @ApiParams (name="mobile", type="string", required=true, description="联系人手机号")
  63 + * @ApiParams (name="license", type="string", required=true, description="营业执照")
  64 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  65 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  66 + * @ApiReturn ({
  67 + 'code':'1',
  68 + 'msg':'返回成功'
  69 + })
  70 + */
  71 + public function store_add()
  72 + {
  73 +// $param = (new RecruitValidate())->goCheck('add');
  74 + $order_sn = $param['order_sn'] = get_order_sn();
  75 + $pay_data = [];
  76 + if($this->auth->end_time > time()) {
  77 + $param['status'] = 2;
  78 + } else {
  79 + $param['status'] = 1;
  80 + // 获取小程序配置
  81 + $options = \config('miniprogram.basic');
  82 + $app = new Application($options);
  83 + $payment = $app->payment;
  84 + // 获取支付参数
  85 + $attributes = [
  86 + 'body' => '发布招募合伙人',
  87 + 'out_trade_no' => $order_sn,
  88 + 'total_fee' => 1, // $param['money'] * 100
  89 + 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
  90 + 'notify_url' => url('index/ajax/notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  91 + 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  92 + 'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),
  93 + ];
  94 + $order = new Order($attributes);
  95 + $order_result = $payment->pay($order);
  96 + if($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {
  97 + $prepayId = $order_result->prepay_id;
  98 + } else {
  99 + $this->error($order_result['return_msg']);
  100 + }
  101 + }
  102 + Db::startTrans();
  103 + $result = false;
  104 + $result_invite = true;
  105 + try{
  106 + $param['user_id'] = $this->auth->id;
  107 + $result = $this->store_model->add($param);
  108 + $id = $this->store_model->id;
  109 + Db::commit();
  110 + } catch (PDOException $e) {
  111 + Db::rollback();
  112 + $this->error($e->getMessage());
  113 + } catch (Exception $e) {
  114 + Db::rollback();
  115 + $this->error($e->getMessage());
  116 + }
  117 + if(!$result || !$result_invite) {
  118 + $this->error('申请提交失败');
  119 + }
  120 + $this->success('申请提交成功',['id'=>$id,'status'=>$param['status'],'pay_data'=>$pay_data]);
  121 + }
  122 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class Store extends Base
  8 +{
  9 +
  10 +}
@@ -362,3 +362,13 @@ if (!function_exists('hsv2rgb')) { @@ -362,3 +362,13 @@ if (!function_exists('hsv2rgb')) {
362 ]; 362 ];
363 } 363 }
364 } 364 }
  365 +
  366 +if(!function_exists('get_order_sn')) {
  367 +
  368 + function get_order_sn()
  369 + {
  370 + // 获取毫秒
  371 + $micro = explode('.',explode(' ',microtime())[0])[1];
  372 + return date('YmdHis').substr($micro,0,5).rand(0,9);
  373 + }
  374 +}
@@ -36,4 +36,5 @@ return array ( @@ -36,4 +36,5 @@ return array (
36 'mail_verify_type' => '2', 36 'mail_verify_type' => '2',
37 'mail_from' => '10000@qq.com', 37 'mail_from' => '10000@qq.com',
38 'contact' => '联系我们联系我们022-12345678', 38 'contact' => '联系我们联系我们022-12345678',
  39 + 'settled' => '上架入驻协议',
39 ); 40 );
此 diff 太大无法显示。