ShopController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Lib\Youzan\YouzanApi;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. use Illuminate\Support\Facades\Input;
  7. use \View;
  8. use \DB;
  9. class ShopController extends Controller
  10. {
  11. public function indexAction(){
  12. $list = DB::table('shop')->where('type',Input::get('type',1))->get();
  13. return View::make('admin.shopList',['list'=>$list]);
  14. }
  15. public function addAction(Request $request){
  16. if($request->isMethod('post')){
  17. $validate = \Validator::make($request->input(),[
  18. 'shopname'=>"required",
  19. 'app_id'=>"required",
  20. 'app_secret'=>"required"
  21. ],[
  22. 'required'=>":attribute必填项不能为空",
  23. ],[
  24. 'shopname'=>'用户名',
  25. 'app_id'=>'AppId',
  26. 'app_secret'=>'secret'
  27. ]);
  28. if($validate->fails()){
  29. return \redirect()->back()->withErrors($validate)->withInput();
  30. }
  31. $res = DB::table('shop')->insert([
  32. 'shopname'=>Input::get('shopname'),
  33. 'app_id'=>Input::get('app_id'),
  34. 'app_secret'=>Input::get('app_secret'),
  35. 'type' => Input::get('type'),
  36. 'savePic' => Input::get('savePic'),
  37. 'delivery_template_id' => Input::get('delivery_template_id')
  38. ]);
  39. if($res){
  40. return \Redirect::route('shop',['type'=>Input::get('type')]);
  41. }
  42. else{
  43. return \Redirect::to('shop')->with('messag','添加失败');
  44. }
  45. }
  46. return View::make('admin.shopform_add');
  47. }
  48. public function updateAction(Request $request,$id){
  49. $id = intval($id);
  50. $data = DB::table('shop')->where('id',$id)->first();
  51. if($request->isMethod('post')){
  52. $validate = \Validator::make($request->input(),[
  53. 'shopname'=>"required",
  54. 'app_id'=>"required",
  55. 'app_secret'=>"required"
  56. ],[
  57. 'required'=>":attribute必填项不能为空",
  58. ],[
  59. 'shopname'=>'用户名',
  60. 'app_id'=>'AppId',
  61. 'app_secret'=>'secret'
  62. ]);
  63. if($validate->fails()){
  64. return \redirect()->back()->withErrors($validate)->withInput();
  65. }
  66. $res = DB::table('shop')->where('id',$id)->update(
  67. [
  68. 'shopname'=>Input::get('shopname'),
  69. 'app_id'=>Input::get('app_id'),
  70. 'app_secret'=>Input::get('app_secret'),
  71. 'delivery_template_id' => Input::get('delivery_template_id'),
  72. 'savePic' => Input::get('savePic'),
  73. 'type' => Input::get('type')
  74. ]
  75. );
  76. if($res){
  77. return \Redirect::route('shop',['type'=>Input::get('type')]);
  78. }
  79. else{
  80. return \Redirect::to('shop')->with('messag','添加失败');
  81. }
  82. }
  83. $data = !$data ? []:$data;
  84. return View::make('admin.shopform',['infos'=>$data]);
  85. }
  86. /**
  87. * 同步店铺分类
  88. */
  89. public function syncCategoryAction(){
  90. $type = Input::get('type');
  91. $shop = \DB::table('shop')->find(Input::get('shop'));
  92. if($type == 1 && $shop){
  93. $yzApi = YouzanApi::getInstance($shop->app_id, $shop->app_secret);
  94. }
  95. }
  96. public function demo(){
  97. $appId = '58fb8f0606bdb5ef45'; //请填入你有赞店铺后台-营销-有赞API的AppId
  98. $appSecret = '1342d112176385ebeb5eaf2f98431ee9';//请填入你有赞店铺后台-营销-有赞API的AppSecret
  99. $client = new \YZSignClient($appId, $appSecret);
  100. //$method = 'youzan.shop.get';//要调用的api名称
  101. $method = 'youzan.logistics.template.get';//要调用的api名称
  102. $methodVersion = '3.0.0';//要调用的api版本号
  103. $params = ['template_id'=>398698];
  104. dd( $client->post($method,$methodVersion,$params));
  105. }
  106. }