Config.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\model\express;
  11. use app\model\store\Store;
  12. use app\model\system\Config as ConfigModel;
  13. use app\model\BaseModel;
  14. /**
  15. * 配送配置
  16. */
  17. class Config extends BaseModel
  18. {
  19. /*********************************************************************** 物流配送 start ***********************************************************************/
  20. /**
  21. * 物流配送配置
  22. * @param $site_id
  23. * @return \multitype
  24. */
  25. public function getExpressConfig($site_id)
  26. {
  27. $config = new ConfigModel();
  28. $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_CONFIG' ] ]);
  29. if (empty($res[ 'data' ][ 'value' ])) {
  30. $res[ 'data' ][ 'value' ] = [
  31. 'express_name' => '快递发货'
  32. ];
  33. }
  34. return $res;
  35. }
  36. /**
  37. * 设置物流配送配置
  38. * @param $data
  39. * @param $is_use
  40. * @param $site_id
  41. * @return array
  42. */
  43. public function setExpressConfig($data, $is_use, $site_id)
  44. {
  45. if ($site_id === '') {
  46. return $this->error('', 'REQUEST_SITE_ID');
  47. }
  48. $config = new ConfigModel();
  49. $res = $config->setConfig($data, '物流配送设置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_CONFIG' ] ]);
  50. return $res;
  51. }
  52. /*********************************************************************** 物流配送 end ***********************************************************************/
  53. /*********************************************************************** 门店自提 start ***********************************************************************/
  54. /**
  55. * 门店自提配置
  56. * @param $site_id
  57. * @return \multitype
  58. */
  59. public function getStoreConfig($site_id)
  60. {
  61. $config = new ConfigModel();
  62. $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_STORE_CONFIG' ] ]);
  63. if (empty($res[ 'data' ][ 'value' ])) {
  64. $res[ 'data' ][ 'value' ] = [
  65. 'store_name' => '门店自提'
  66. ];
  67. }
  68. return $res;
  69. }
  70. /**
  71. * 设置门店自提配置
  72. * @param $data
  73. * @param $is_use
  74. * @param $site_id
  75. * @return array
  76. */
  77. public function setStoreConfig($data, $is_use, $site_id)
  78. {
  79. if ($site_id === '') {
  80. return $this->error('', 'REQUEST_SITE_ID');
  81. }
  82. if ($is_use == 1) {
  83. $store_model = new Store();
  84. $check_result = $store_model->checkIscanStoreTrade($site_id);
  85. if($check_result['code'] < 0)
  86. return $check_result;
  87. }
  88. $config = new ConfigModel();
  89. $res = $config->setConfig($data, '门店自提配置设置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_STORE_CONFIG' ] ]);
  90. return $res;
  91. }
  92. /**
  93. * 设置门店自提开关
  94. * @param $is_use
  95. * @param $site_id
  96. * @return array
  97. */
  98. public function setStoreIsuse($is_use, $site_id, $app_module = 'shop')
  99. {
  100. if ($site_id === '') {
  101. return $this->error('', 'REQUEST_SITE_ID');
  102. }
  103. if ($is_use == 1) {
  104. $store_model = new Store();
  105. $check_result = $store_model->checkIscanStoreTrade($site_id);
  106. if($check_result['code'] < 0)
  107. return $check_result;
  108. }
  109. $config = new ConfigModel();
  110. $res = $config->modifyConfigIsUse($is_use, [['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'EXPRESS_STORE_CONFIG']]);
  111. return $res;
  112. }
  113. /*********************************************************************** 门店自提 end ***********************************************************************/
  114. /*********************************************************************** 外卖配送 start ***********************************************************************/
  115. /**
  116. * 外卖配送配置
  117. * @param $site_id
  118. * @return array
  119. */
  120. public function getLocalDeliveryConfig($site_id)
  121. {
  122. $config = new ConfigModel();
  123. $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_LOCAL_DELIVERY_CONFIG' ] ]);
  124. if (empty($res[ 'data' ][ 'value' ])) {
  125. $res[ 'data' ][ 'value' ] = [
  126. 'local_name' => '同城配送'
  127. ];
  128. }
  129. return $res;
  130. }
  131. /**
  132. * 设置外卖配送配置
  133. * @param $data
  134. * @param $is_use
  135. * @param $site_id
  136. * @return array
  137. */
  138. public function setLocalDeliveryConfig($data, $is_use, $site_id)
  139. {
  140. if ($site_id === '') {
  141. return $this->error('', '缺少必须参数站点id');
  142. }
  143. if($is_use == 1){
  144. $local_model = new Local();
  145. $check_result = $local_model->checkIsCanTradeLocal($site_id);
  146. if($check_result['code'])
  147. return $check_result;
  148. }
  149. $config = new ConfigModel();
  150. $res = $config->setConfig($data, '同城配送配置设置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_LOCAL_DELIVERY_CONFIG' ] ]);
  151. return $res;
  152. }
  153. /*********************************************************************** 外卖配送 end ***********************************************************************/
  154. /**
  155. * 外卖配送配置
  156. * @param $site_id
  157. * @return array
  158. */
  159. public function getDeliverTypeSort($site_id)
  160. {
  161. $config = new ConfigModel();
  162. $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'DELIVERY_SORT_CONFIG' ] ]);
  163. if (empty($res[ 'data' ][ 'value' ])) {
  164. $res[ 'data' ][ 'value' ] = [
  165. 'deliver_type' => 'local,express,store'
  166. ];
  167. }
  168. return $res;
  169. }
  170. public function setDeliverTypeSort($data, $site_id)
  171. {
  172. if ($site_id === '') {
  173. return $this->error('', '缺少必须参数站点id');
  174. }
  175. $config = new ConfigModel();
  176. $res = $config->setConfig($data, '配置方式排序设置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'DELIVERY_SORT_CONFIG' ] ]);
  177. return $res;
  178. }
  179. /**
  180. * 配送方式列表
  181. */
  182. public function getExpressTypeList($site_id)
  183. {
  184. //外卖配送
  185. $local = $this->getLocalDeliveryConfig($site_id)[ 'data' ][ 'value' ] ?? [];
  186. $store = $this->getStoreConfig($site_id)[ 'data' ][ 'value' ] ?? [];
  187. $express = $this->getExpressConfig($site_id)[ 'data' ][ 'value' ] ?? [];
  188. return [ 'express' => $express[ 'express_name' ], 'store' => $store[ 'store_name' ], 'local' => $local[ 'local_name' ] ];
  189. }
  190. /**
  191. * 获取已启用的配送方式
  192. * @param $site_id
  193. */
  194. public function getEnabledExpressType($site_id){
  195. $local = $this->getLocalDeliveryConfig($site_id)[ 'data' ];
  196. $store = $this->getStoreConfig($site_id)[ 'data' ];
  197. $express = $this->getExpressConfig($site_id)[ 'data' ];
  198. $express_type = [];
  199. if ($express['is_use']) {
  200. $express_type['express'] = [
  201. 'name' => $express['value'][ 'express_name' ],
  202. 'icon' => 'iconwuliu',
  203. 'desc' => '支持'.$express['value'][ 'express_name' ].'的商品在购买后将会通过快递的方式进行配送,可在订单中查看物流信息'
  204. ];
  205. }
  206. if ($store['is_use']) {
  207. $express_type['store'] = [
  208. 'name' => $store['value'][ 'store_name' ],
  209. 'icon' => 'icondianpu',
  210. 'desc' => '支持'.$store['value'][ 'store_name' ].'的商品在购买后用户可自行到下单时所选择的自提点进行提货'
  211. ];
  212. }
  213. if ($local['is_use']) {
  214. $express_type['local'] = [
  215. 'name' => $local['value'][ 'local_name' ],
  216. 'icon' => 'iconwaimaifuwu',
  217. 'desc' => '支持'.$local['value'][ 'local_name' ].'的商品在购买后平台将安排配送人员配送到用户指定的收货地点'
  218. ];
  219. }
  220. return $express_type;
  221. }
  222. }