123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Lib\Youzan\YouzanApi;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Input;
- use \View;
- use \DB;
- class ShopController extends Controller
- {
- public function indexAction(){
- $list = DB::table('shop')->where('type',Input::get('type',1))->get();
- return View::make('admin.shopList',['list'=>$list]);
- }
- public function addAction(Request $request){
- if($request->isMethod('post')){
- $validate = \Validator::make($request->input(),[
- 'shopname'=>"required",
- 'app_id'=>"required",
- 'app_secret'=>"required"
- ],[
- 'required'=>":attribute必填项不能为空",
- ],[
- 'shopname'=>'用户名',
- 'app_id'=>'AppId',
- 'app_secret'=>'secret'
- ]);
- if($validate->fails()){
- return \redirect()->back()->withErrors($validate)->withInput();
- }
- $res = DB::table('shop')->insert([
- 'shopname'=>Input::get('shopname'),
- 'app_id'=>Input::get('app_id'),
- 'app_secret'=>Input::get('app_secret'),
- 'type' => Input::get('type'),
- 'savePic' => Input::get('savePic'),
- 'delivery_template_id' => Input::get('delivery_template_id')
- ]);
- if($res){
- return \Redirect::route('shop',['type'=>Input::get('type')]);
- }
- else{
- return \Redirect::to('shop')->with('messag','添加失败');
- }
- }
- return View::make('admin.shopform_add');
- }
- public function updateAction(Request $request,$id){
- $id = intval($id);
- $data = DB::table('shop')->where('id',$id)->first();
- if($request->isMethod('post')){
- $validate = \Validator::make($request->input(),[
- 'shopname'=>"required",
- 'app_id'=>"required",
- 'app_secret'=>"required"
- ],[
- 'required'=>":attribute必填项不能为空",
- ],[
- 'shopname'=>'用户名',
- 'app_id'=>'AppId',
- 'app_secret'=>'secret'
- ]);
- if($validate->fails()){
- return \redirect()->back()->withErrors($validate)->withInput();
- }
- $res = DB::table('shop')->where('id',$id)->update(
- [
- 'shopname'=>Input::get('shopname'),
- 'app_id'=>Input::get('app_id'),
- 'app_secret'=>Input::get('app_secret'),
- 'delivery_template_id' => Input::get('delivery_template_id'),
- 'savePic' => Input::get('savePic'),
- 'type' => Input::get('type')
- ]
- );
- if($res){
- return \Redirect::route('shop',['type'=>Input::get('type')]);
- }
- else{
- return \Redirect::to('shop')->with('messag','添加失败');
- }
- }
- $data = !$data ? []:$data;
- return View::make('admin.shopform',['infos'=>$data]);
- }
- /**
- * 同步店铺分类
- */
- public function syncCategoryAction(){
- $type = Input::get('type');
- $shop = \DB::table('shop')->find(Input::get('shop'));
- if($type == 1 && $shop){
- $yzApi = YouzanApi::getInstance($shop->app_id, $shop->app_secret);
- }
- }
- public function demo(){
- $appId = '58fb8f0606bdb5ef45'; //请填入你有赞店铺后台-营销-有赞API的AppId
- $appSecret = '1342d112176385ebeb5eaf2f98431ee9';//请填入你有赞店铺后台-营销-有赞API的AppSecret
- $client = new \YZSignClient($appId, $appSecret);
- //$method = 'youzan.shop.get';//要调用的api名称
- $method = 'youzan.logistics.template.get';//要调用的api名称
- $methodVersion = '3.0.0';//要调用的api版本号
- $params = ['template_id'=>398698];
- dd( $client->post($method,$methodVersion,$params));
- }
- }
|