ShMethodController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * 用途:配送方式配置控制器
  4. * 谁用:供货商系统管理员
  5. * 解决什么问题:提供配送方式(送货、自取、跑腿、快递、物流)配置的获取和保存接口
  6. */
  7. namespace ghs\controllers;
  8. use bizGhs\order\classes\ShMethodClass;
  9. use Yii;
  10. use common\components\util;
  11. class ShMethodController extends BaseController
  12. {
  13. /**
  14. * 获取指定配送方式的配置
  15. * GET 参数:
  16. * - style: 配送类型 (0: 送货, 1: 自取, 2: 跑腿, 3: 快递, 4: 物流)
  17. */
  18. public function actionGetConfig()
  19. {
  20. $style = Yii::$app->request->get('style', 0);
  21. try {
  22. $config = ShMethodClass::getConfig($this->shopId, $this->mainId, $style);
  23. util::success($config);
  24. } catch (\Exception $e) {
  25. util::fail($e->getMessage());
  26. }
  27. }
  28. /**
  29. * 获取门店所有的5种配送方式配置
  30. * 如果数据库里没有,则取默认配置进行初始化
  31. */
  32. public function actionGetAllMethod()
  33. {
  34. try {
  35. $configs = ShMethodClass::getAllConfigs($this->shopId, $this->mainId);
  36. util::success($configs);
  37. } catch (\Exception $e) {
  38. util::fail($e->getMessage());
  39. }
  40. }
  41. /**
  42. * 获取所有配送方式的排序和别名信息
  43. */
  44. public function actionGetSorts()
  45. {
  46. try {
  47. $sorts = ShMethodClass::getSorts($this->mainId);
  48. util::success($sorts);
  49. } catch (\Exception $e) {
  50. util::fail($e->getMessage());
  51. }
  52. }
  53. /**
  54. * 保存指定配送方式的配置
  55. * POST 参数:
  56. * - id: 配置ID(可选)
  57. * - style: 配送类型 (0: 送货, 1: 自取, 2: 跑腿, 3: 快递, 4: 物流)
  58. * - name: 名称
  59. * - calcType: 算运费方式 (0: 用跑腿, 1: 用自定义)
  60. * - status: 状态 (0: 禁用, 1: 启用)
  61. * - sort: 排序
  62. * - minAmount: 最低消费金额
  63. * - minNum: 最低消费数量
  64. * - unMeet: 不满条件处理方式 (0: 收运费, 1: 收包装费, 2: 不能下单)
  65. * - unMeetFee: 运费/包装费金额
  66. * - startKm: 起步公里数
  67. * - startPrice: 起步价格
  68. * - perKmPrice: 超出起步每公里加价
  69. * - changeRate: 临时涨价比例 (%)
  70. * - explains: 说明项列表 (二维数组,包含 explain, color, fontWeight, sort)
  71. * - reduceRules: 跑腿满减规则列表 (二维数组,包含 meetNum, meetAmount, freeKm, sort)
  72. */
  73. public function actionSaveConfig()
  74. {
  75. $post = Yii::$app->request->post();
  76. try {
  77. ShMethodClass::saveConfig($this->shopId, $this->mainId, $post);
  78. util::complete('保存成功');
  79. } catch (\Exception $e) {
  80. util::fail($e->getMessage());
  81. }
  82. }
  83. }