ShMethodController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. * 获取所有配送方式的排序和别名信息
  30. */
  31. public function actionGetSorts()
  32. {
  33. try {
  34. $sorts = ShMethodClass::getSorts($this->shopId, $this->mainId);
  35. util::success($sorts);
  36. } catch (\Exception $e) {
  37. util::fail($e->getMessage());
  38. }
  39. }
  40. /**
  41. * 保存指定配送方式的配置
  42. * POST 参数:
  43. * - id: 配置ID(可选)
  44. * - style: 配送类型 (0: 送货, 1: 自取, 2: 跑腿, 3: 快递, 4: 物流)
  45. * - alias: 别名
  46. * - status: 状态 (0: 禁用, 1: 启用)
  47. * - sort: 排序
  48. * - minAmount: 最低消费金额
  49. * - minNum: 最低消费数量
  50. * - unMeet: 不满条件处理方式 (0: 收运费, 1: 不能下单, 2: 收包装费)
  51. * - unMeetFee: 运费/包装费金额
  52. * - startKm: 起步公里数
  53. * - startPrice: 起步价格
  54. * - perKmPrice: 超出起步每公里加价
  55. * - changeRate: 临时涨价比例 (%)
  56. * - explains: 说明项列表 (二维数组,包含 explain, color, fontWeight, sort)
  57. * - reduceRules: 跑腿满减规则列表 (二维数组,包含 meetNum, meetAmount, freeKm, sort)
  58. */
  59. public function actionSaveConfig()
  60. {
  61. $post = Yii::$app->request->post();
  62. try {
  63. ShMethodClass::saveConfig($this->shopId, $this->mainId, $post);
  64. util::complete('保存成功');
  65. } catch (\Exception $e) {
  66. util::fail($e->getMessage());
  67. }
  68. }
  69. }