ShMethodController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\order\classes\ShMethodClass;
  4. use bizHd\ghs\classes\GhsClass;
  5. use Yii;
  6. use common\components\util;
  7. class ShMethodController extends BaseController
  8. {
  9. /**
  10. * 获取供货商所有的5种配送方式配置
  11. * 如果数据库里没有,则取默认配置进行初始化
  12. */
  13. public function actionGetAllMethod()
  14. {
  15. $ghsId = Yii::$app->request->get('ghsId', 0);
  16. $ghs = GhsClass::getById($ghsId);
  17. if (empty($ghs)) {
  18. util::fail('没有供货商信息');
  19. }
  20. if ($ghs['ownMainId'] != $this->mainId) {
  21. util::fail('不是你的供货商');
  22. }
  23. $shopId = $ghs['shopId'] ?? 0;
  24. $mainId = $ghs['mainId'] ?? 0;
  25. if (!in_array($shopId, [36523, 0])) {
  26. util::success([]);
  27. }
  28. try {
  29. $customId = $ghs['customId'] ?? 0;
  30. $configs = ShMethodClass::getAllConfigs($shopId, $mainId);
  31. if ($customId > 0) {
  32. $hasPaidSendCost = ShMethodClass::isSendCostPaidToday($customId);
  33. $hasPaidPackCost = ShMethodClass::isPaidToday($customId);
  34. foreach ($configs as &$config) {
  35. $unMeet = (int)($config['unMeet'] ?? 0);
  36. // 如果是加收运费或加收包装费,并且今天已经收过对应的费用
  37. // 则将前端展示的条件清空(设为0),从而不再显示要收附加费的提示
  38. if ($unMeet === 0 && $hasPaidSendCost) {
  39. $config['minAmount'] = 0;
  40. $config['minNum'] = 0;
  41. $config['unMeetFee'] = 0;
  42. } elseif ($unMeet === 2 && $hasPaidPackCost) {
  43. $config['minAmount'] = 0;
  44. $config['minNum'] = 0;
  45. $config['unMeetFee'] = 0;
  46. }
  47. }
  48. }
  49. util::success(['method' => $configs]);
  50. } catch (\Exception $e) {
  51. util::fail($e->getMessage());
  52. }
  53. }
  54. }