DeliveryShopController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 actionBalance()
  16. {
  17. $get = Yii::$app->request->get();
  18. $platform = $get['platform'];
  19. $ShopService = new ShopService($this->mainId, $platform);
  20. $balance = $ShopService->getBalance($platform);
  21. $deliveryAuthToken = DeliveryAuthTokenClass::getByCondition(['platform'=>$platform, 'mainId'=>$this->mainId], true);
  22. if(!$deliveryAuthToken){
  23. util::fail('配送平台未授权');
  24. }
  25. $deliveryAuthToken->balance = $balance;
  26. $deliveryAuthToken->save();
  27. util::success(['balance'=>$balance]);
  28. }
  29. public function actionStoreList()
  30. {
  31. $get = Yii::$app->request->get();
  32. $platform = $get['platform'];
  33. $ShopService = new ShopService($this->mainId, $platform);
  34. $stores = $ShopService->getMerchantStores($platform);
  35. util::success($stores);
  36. }
  37. public function actionBindStore(){
  38. $post = Yii::$app->request->post();
  39. $platform = $post['platform'];
  40. $storeId = $post['shopId'];
  41. $ShopService = new ShopService($this->mainId, $platform);
  42. $re = $ShopService->bindStore($this->mainId, $platform, $storeId);
  43. if(!$re){
  44. util::fail('绑定门店失败');
  45. }
  46. util::success('绑定成功');
  47. }
  48. public function actionUnbindStore(){
  49. $post = Yii::$app->request->post();
  50. $platform = $post['platform'];
  51. $storeId = $post['shopId'];
  52. $ShopService = new ShopService($this->mainId, $platform);
  53. $re = $ShopService->unbindStore($this->mainId, $platform, $storeId);
  54. if(!$re){
  55. util::fail('解绑门店失败');
  56. }
  57. util::success('解绑门店成功');
  58. }
  59. public function actionStoreDetail()
  60. {
  61. $post = Yii::$app->request->post();
  62. $platform = $post['platform'];
  63. $delivery = DeliveryAuthTokenClass::getByCondition(['platform'=>$platform, 'mainId'=>$this->mainId], true);
  64. if(!$delivery){
  65. util::fail('配送平台不存在');
  66. }
  67. $ShopService = new ShopService($this->mainId, $platform);
  68. $re = $ShopService->storeDetail($this->mainId, $platform, $delivery->shopId);
  69. if(!$re){
  70. util::fail('获取门店详情失败');
  71. }
  72. util::success($re, '获取门店详情成功');
  73. }
  74. public function actionUpdateStore()
  75. {
  76. $post = Yii::$app->request->post();
  77. $platform = $post['platform'];
  78. $delivery = DeliveryAuthTokenClass::getByCondition(['platform'=>$platform, 'mainId'=>$this->mainId], true);
  79. if(!$delivery){
  80. util::fail('配送平台不存在');
  81. }
  82. $ShopService = new ShopService($this->mainId, $platform);
  83. $re = $ShopService->updateStore($delivery->shopId, $platform, $post);
  84. if(!$re){
  85. util::fail('修改门店详情失败');
  86. }
  87. util::success($re, '修改门店详情成功');
  88. }
  89. }