ShippingTemplateRegion.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\common\model\store\shipping;
  3. use app\common\model\BaseModel;
  4. use app\common\repositories\store\CityAreaRepository;
  5. class ShippingTemplateRegion extends BaseModel
  6. {
  7. /**
  8. * Author:Qinii
  9. * Date: 2020/5/6
  10. * Time: 14:20
  11. * @return string
  12. */
  13. public static function tablePk(): string
  14. {
  15. return 'shipping_template_region_id';
  16. }
  17. /**
  18. * Author:Qinii
  19. * Date: 2020/5/6
  20. * Time: 14:20
  21. * @return string
  22. */
  23. public static function tableName(): string
  24. {
  25. return 'shipping_template_region';
  26. }
  27. public function getCityIDsAttr($value, $data)
  28. {
  29. if (!$data['city_id']) return [];
  30. $city_id = explode('/', $data['city_id']);
  31. $data = app()->make(CityAreaRepository::class)->search([])->where('id', 'in', $city_id)->select();
  32. $result = [];
  33. foreach ($data as $v) {
  34. $result[] = array_map('intval', explode('/', trim($v['path'] . $v['id'], '/')));
  35. }
  36. return $result;
  37. }
  38. public function setCityIdAttr($value)
  39. {
  40. return '/'.( implode('/',$value)).'/';
  41. }
  42. }