SettingController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\food\controllers;
  8. use app\models\Option;
  9. use app\models\District;
  10. use app\models\Store;
  11. use app\utils\Alipay\AlipayProfit;
  12. class SettingController extends BaseController
  13. {
  14. public function actionGetSetting()
  15. {
  16. $data = Option::get('food_book', get_store_id(), 'store', [
  17. 'name' => '',
  18. 'logo' => '',
  19. 'address' => '',
  20. 'phone' => '',
  21. 'service' => '',
  22. 'open_time' => '',
  23. 'categroy' => 'B0001',
  24. 'business_address' => [],
  25. 'switch' => 1,
  26. 'person' => 5,
  27. 'time' => [],
  28. 'store_pic' => [],
  29. 'tips' => '',
  30. 'say_time' => '',
  31. 'description' => ''
  32. ]);
  33. $data = is_string($data['value']) ? json_decode($data['value'], true) : $data['value'];
  34. if (!empty($data['business_address'])) {
  35. $province_code = District::findOne(['adcode' => $data['business_address']['province_code']]);
  36. $city_code = District::findOne(['adcode' => $data['business_address']['city_code']]);
  37. $district_code = District::findOne(['adcode' => $data['business_address']['district_code']]);
  38. $data['business_address'] = [
  39. 'province_id' => $province_code->id,
  40. 'city_id' => $city_code->id,
  41. 'district_id' => $district_code->id,
  42. ];
  43. }
  44. return [
  45. 'code' => 0,
  46. 'msg' => 'success',
  47. 'data' => $data,
  48. ];
  49. }
  50. public function actionSetLogo()
  51. {
  52. $logo = post_params('logo');
  53. if (!$logo) {
  54. return [
  55. 'code' => 1,
  56. 'msg' => '缺少必要参数',
  57. ];
  58. }
  59. $data = Option::get('food_book', get_store_id(), 'store', [
  60. 'name' => '',
  61. 'logo' => '',
  62. 'address' => '',
  63. 'phone' => '',
  64. 'service' => '',
  65. 'open_time' => '',
  66. 'categroy' => 'B0001',
  67. 'business_address' => [],
  68. 'switch' => 1,
  69. 'person' => 5,
  70. 'time' => [],
  71. 'store_pic' => [],
  72. 'tips' => '',
  73. 'say_time' => '',
  74. ]);
  75. $data = is_string($data['value']) ? json_decode($data['value'], true) : $data['value'];
  76. $data['logo'] = $logo;
  77. Option::set('food_book', json_encode($data), get_store_id(), 'store');
  78. return [
  79. 'code' => 0,
  80. 'msg' => '保存成功',
  81. ];
  82. }
  83. public function actionSetSetting()
  84. {
  85. $data = post_params('data');
  86. $cityInfo = post_params('cityInfo');
  87. if (!$data || !$cityInfo) {
  88. return [
  89. 'code' => 1,
  90. 'msg' => '缺少必要参数',
  91. ];
  92. }
  93. $province_code = District::findOne($cityInfo['province_id']);
  94. $city_code = District::findOne($cityInfo['city_id']);
  95. $district_code = District::findOne($cityInfo['district_id']);
  96. $data['business_address'] = [
  97. 'province_code' => $province_code->adcode,
  98. 'city_code' => $city_code->adcode,
  99. 'district_code' => $district_code->adcode,
  100. ];
  101. // 创建蚂蚁门店
  102. $store = Store::findOne(get_store_id());
  103. if (empty($store->shop_id)) {
  104. $array = [
  105. 'business_address' => [
  106. 'province_code' => $province_code->adcode,
  107. 'city_code' => $city_code->adcode,
  108. 'district_code' => $district_code->adcode,
  109. 'address' => $data['address'],
  110. ],
  111. 'contact_mobile' => $data['phone'],
  112. 'shop_category' => $data['category'],
  113. 'store_id' => 'NO' . get_store_id(),
  114. 'shop_type' => '01',
  115. 'ip_role_id' => Option::getAlipayConfig()['user_id'],
  116. 'shop_name' => $data['name']
  117. ];
  118. $res = AlipayProfit::shop_create($array);
  119. \Yii::warning(['<========= 创建蚂蚁门店 ==========>', $array, $res]);
  120. // Todo 暂时不返回
  121. // if ($res['code'] != 0) {
  122. // return [
  123. // 'code' => 1,
  124. // 'msg' => $res['msg'],
  125. // ];
  126. // }
  127. }
  128. Option::set('food_book', json_encode($data), get_store_id(), 'store');
  129. return [
  130. 'code' => 0,
  131. 'msg' => '保存成功',
  132. ];
  133. }
  134. }