ShMethodController.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 (isset($ghs['homeRule']) && $ghs['homeRule'] == 1) {
  32. foreach ($configs as &$config) {
  33. if ($config['style'] == 0) {
  34. $config['status'] = $ghs['home'] ?? 0;
  35. $config['minAmount'] = $ghs['homeAmount'] ?? 0;
  36. $config['minNum'] = $ghs['homeNum'] ?? 0;
  37. $config['unMeet'] = $ghs['homeUnMeet'] ?? 0;
  38. $config['unMeetFee'] = $ghs['homeUnFee'] ?? 0;
  39. }
  40. }
  41. }
  42. if ($customId > 0) {
  43. $hasPaidSendCost = ShMethodClass::isSendCostPaidToday($customId);
  44. $hasPaidPackCost = ShMethodClass::isPaidToday($customId);
  45. foreach ($configs as &$config) {
  46. $unMeet = (int)($config['unMeet'] ?? 0);
  47. // 如果是加收运费或加收包装费,并且今天已经收过对应的费用
  48. // 则将前端展示的条件清空(设为0),从而不再显示要收附加费的提示
  49. if ($unMeet === 0 && $hasPaidSendCost) {
  50. $config['minAmount'] = 0;
  51. $config['minNum'] = 0;
  52. $config['unMeetFee'] = 0;
  53. } elseif ($unMeet === 2 && $hasPaidPackCost) {
  54. $config['minAmount'] = 0;
  55. $config['minNum'] = 0;
  56. $config['unMeetFee'] = 0;
  57. }
  58. }
  59. }
  60. util::success(['method' => $configs]);
  61. } catch (\Exception $e) {
  62. util::fail($e->getMessage());
  63. }
  64. }
  65. }