Ver código fonte

更新接口

dyjh 6 anos atrás
pai
commit
2e748b96dd

+ 24 - 15
app/Http/Controllers/Api/V1/AlbumController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -158,6 +158,7 @@ class AlbumController extends Controller
      * @apiPermission none
      * @apiVersion 0.1.0
      * @apiParam {int}    [code]
+     * @apiParam {int}    [agent_id]  经销商id
      * @apiParam {int}    [store_id]  商户id
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
@@ -226,15 +227,13 @@ class AlbumController extends Controller
                 $add['store_id'] = $datas['store_id'];
                 $res = AlbumXyxUserModel::create($add);
                 if($res){
-                    $data_user = AlbumXyxUserModel::where('wechat_open_id',$res['openid'])->first();
+                    $check = AlbumXyxUserModel::where('wechat_open_id',$res['openid'])->first();
                     $user = [
-
-                        'user_id'=>$data_user['id'],
-                        'avatar'=>$data_user['avatar'],
-                        'username'=>$data_user['username'],
+                        'user_id'=>$check['id'],
+                        'avatar'=>$check['avatar'],
+                        'username'=>$check['username'],
                         'is_agent'=>0,
                         'agent_id'=>'',
-
                     ];
                 }else{
                     $user=[
@@ -266,7 +265,16 @@ class AlbumController extends Controller
 
             }
 
-        return $this->api($user);
+        if (Auth::loginUsingId($check->id)) {
+            $userAuth = Auth::user();
+            $save['up_agent_id'] = $request->input('agent_id');
+            $user->save();
+            $token = $userAuth->createToken($userAuth->id . '-' . $userAuth->openid)->accessToken;
+            return $this->api(compact('token', 'user', 'session_key'));
+        } else {
+
+            return $this->error(ErrorCode::INCORRECT_USER_OR_PASS);
+        }
     }
 
 
@@ -314,7 +322,6 @@ class AlbumController extends Controller
      * @apiParam {int}    [status]  状态  1 只选择热销 2 只选择最新上市 3只选择一个风格 4 同时选择热销和最新上市 5同时选择热销和风格 6同时选择最新上市和风格 7全选 0全不选
      * @apiParam {int}    [style]  风格
      * @apiParam {int}    [store_id]  商户id
-     * @apiParam {int}    [agent_id]  经销商id
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
      * {
@@ -339,6 +346,7 @@ class AlbumController extends Controller
      */
     public function albumGoods(Request $request)
     {
+        $userAuth = Auth('api')->user();
         $validator = Validator::make($request->all(), [
             'cat_id' => 'required',
             'store_id' => 'required',
@@ -379,7 +387,7 @@ class AlbumController extends Controller
         foreach($goods as $key =>$val){
             if(isset($data['agent_id'])){
                // dd(111);
-                $check = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
+                $check = AlbumProductPriceModel::where([['agent_id',$userAuth->up_agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
                 if($check){
                     $goods[$key]['price'] = $check->price;
                 }else{
@@ -403,7 +411,6 @@ class AlbumController extends Controller
      * @apiPermission none
      * @apiVersion 0.1.0
      * @apiParam {int}    [goods_id]  商品id
-     * @apiParam {int}    [agent_id]  经销商id 模拟值为10
      * @apiParam {int}    [store_id]  商户id 模拟值为0
      * @apiParam {int}    [user_id]  用户id
      * @apiSuccessExample {json} Success-Response:
@@ -427,6 +434,7 @@ class AlbumController extends Controller
      */
     public function albumGoodsDetail(Request $request)
     {
+        $userAuth = Auth('api')->user();
         $validator = Validator::make($request->all(), [
             'goods_id' => 'required',
             'user_id' => 'required',
@@ -443,7 +451,7 @@ class AlbumController extends Controller
         $user_id = request('user_id');
         $goods = AlbumProductModel::where([['id',$goods_id],['store_id',$store_id]])->first();
         if(!empty($goods) && $agent_id != ''){
-            $price = DB::table('album_product_price')->where([['agent_id',$agent_id],['store_id',$store_id],['product_id',$goods['id']]])->first();
+            $price = DB::table('album_product_price')->where([['agent_id',$userAuth->up_agent_id],['store_id',$store_id],['product_id',$goods['id']]])->first();
             if(!empty($price)){
                 $goods->price = $price->price;
                 $goods->mobile = $price->mobile;
@@ -817,6 +825,7 @@ class AlbumController extends Controller
      */
     public function albumSetPrice(Request $request)
     {
+        $userAuth = Auth('api')->user();
         $data = $request->all();
         //print_r($data);
         $save = array();
@@ -825,14 +834,14 @@ class AlbumController extends Controller
             $save['mobile'] = $data['mobile'];
             $product = AlbumProductModel::where('store_id',$data['store_id'])->get();
             foreach($product as $key=>$val){
-                $check = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
+                $check = AlbumProductPriceModel::where([['agent_id',$userAuth->up_agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
                 if(empty($check)){
                     $save['agent_id'] = $data['agent_id'];
                     $save['store_id'] = $data['store_id'];
                     $save['product_id'] = $val['id'];
                     $res = AlbumProductPriceModel::create($save);
                 }else{
-                    $res = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$val['id']]])->update($save);
+                    $res = AlbumProductPriceModel::where([['agent_id',$userAuth->up_agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->update($save);
                 }
                 if(!$res){
                     $return['msg'] = 'error';
@@ -852,14 +861,14 @@ class AlbumController extends Controller
             $return['msg'] = 'success';
         } elseif ($data['type'] == 1){
             $save['price'] = $data['price'];
-            $check = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->first();
+            $check = AlbumProductPriceModel::where([['agent_id',$userAuth->up_agent_id],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->first();
             if(empty($check)){
                 $save['agent_id'] = $data['agent_id'];
                 $save['store_id'] = $data['store_id'];
                 $save['product_id'] = $data['goods_id'];
                 $res = AlbumProductPriceModel::create($save);
             }else{
-                $res = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->update($save);
+                $res = AlbumProductPriceModel::where([['agent_id',$userAuth->up_agent_id],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->update($save);
             }
             if($res){
                 $return['msg'] = 'success';

+ 33 - 0
database/migrations/2018_10_29_110809_add_column_to_album_xyx_user.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddColumnToAlbumXyxUser extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('album_xyx_user', function (Blueprint $table) {
+            //
+            $table->unsignedInteger('up_agent_id')->default(0)->comment('经销商id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('album_xyx_user', function (Blueprint $table) {
+            //
+        });
+    }
+}