DeliveryShopController.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\express\classes\DeliveryAuthTokenClass;
  4. use common\components\util;
  5. use common\components\delivery\services\ShopService;
  6. use Yii;
  7. /**
  8. * 聚合配送 -- 门店相关接口
  9. * Class DeliveryController
  10. * @package ghs\controllers
  11. */
  12. class DeliveryShopController extends BaseController
  13. {
  14. public $guestAccess = [];
  15. // public function actionList()
  16. // {
  17. // $platformList = [];
  18. // $platformLogos = [
  19. // 'data' => ['name'=>'达达', 'logo'=>'📦'],
  20. // 'shunfeng' => ['name'=>'顺丰同城', 'logo'=>'🚚'],
  21. // 'meituan' => ['name'=>'美团', 'logo'=>'🍱'] ,
  22. // 'fengniao' => ['name'=>'蜂鸟', 'logo'=>'🍜'],
  23. // 'huolala' => ['name'=>'货拉拉跑腿', 'logo'=>'🚛'],
  24. // 'shansong' => ['name'=>'闪送', 'logo'=>'⚡'],
  25. // 'didi' => ['name'=>'滴滴', 'logo'=>'🚗'],
  26. // 'uu' => ['name'=>'UU跑腿', 'logo'=>'🛵']
  27. // ];
  28. // $mainId = $this->mainId;
  29. // $allDeliveries = DeliveryAuthTokenClass::getAllByCondition(['mainId'=>$mainId]);
  30. // foreach($allDeliveries as $d){
  31. // $item = [
  32. // 'id'=>$d['platform'],
  33. // 'logo'=>$platformLogos[$d['platform']]['logo'],
  34. // 'name'=>$platformLogos[$d['platform']]['name'],
  35. // 'is_authorized' => true,
  36. // 'balance' => $d['balance']/100.0,
  37. // 'access_type' => 'oauth'
  38. // ];
  39. // $platformList[] = $item;
  40. // }
  41. // util::success(['platformList'=>$platformList]);
  42. // }
  43. public function actionBalance()
  44. {
  45. $get = Yii::$app->request->get();
  46. $platform = $get['platform'];
  47. $ShopService = new ShopService($this->mainId, $platform);
  48. $balance = $ShopService->getBalance($platform);
  49. $deliveryAuthToken = DeliveryAuthTokenClass::getByCondition(['platform'=>$platform, 'mainId'=>$this->mainId], true);
  50. if(!$deliveryAuthToken){
  51. util::fail('配送平台未授权');
  52. }
  53. $deliveryAuthToken->balance = $balance;
  54. $deliveryAuthToken->save();
  55. util::success(['balance'=>$balance]);
  56. }
  57. public function actionStoreList()
  58. {
  59. $get = Yii::$app->request->get();
  60. $platform = $get['platform'];
  61. $ShopService = new ShopService($this->mainId, $platform);
  62. $stores = $ShopService->getMerchantStores($platform);
  63. util::success($stores);
  64. }
  65. public function actionBindStore(){
  66. $post = Yii::$app->request->post();
  67. $platform = $post['platform'];
  68. $storeId = $post['shopId'];
  69. $ShopService = new ShopService($this->mainId, $platform);
  70. $re = $ShopService->bindStore($this->mainId, $platform, $storeId);
  71. if(!$re){
  72. util::fail('绑定门店失败');
  73. }
  74. util::success('绑定成功');
  75. }
  76. public function actionUnbindStore(){
  77. $post = Yii::$app->request->post();
  78. $platform = $post['platform'];
  79. $storeId = $post['shopId'];
  80. $ShopService = new ShopService($this->mainId, $platform);
  81. $re = $ShopService->unbindStore($this->mainId, $platform, $storeId);
  82. if(!$re){
  83. util::fail('解绑门店失败');
  84. }
  85. util::success('解绑门店成功');
  86. }
  87. }