ShippingTemplateRegion.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\store\shipping;
  12. use app\common\model\BaseModel;
  13. use app\common\repositories\store\CityAreaRepository;
  14. class ShippingTemplateRegion extends BaseModel
  15. {
  16. /**
  17. * Author:Qinii
  18. * Date: 2020/5/6
  19. * Time: 14:20
  20. * @return string
  21. */
  22. public static function tablePk(): string
  23. {
  24. return 'shipping_template_region_id';
  25. }
  26. /**
  27. * Author:Qinii
  28. * Date: 2020/5/6
  29. * Time: 14:20
  30. * @return string
  31. */
  32. public static function tableName(): string
  33. {
  34. return 'shipping_template_region';
  35. }
  36. public function getCityIDsAttr($value, $data)
  37. {
  38. if (!$data['city_id']) return [];
  39. $city_id = explode('/', $data['city_id']);
  40. $data = app()->make(CityAreaRepository::class)->search([])->where('id', 'in', $city_id)->select();
  41. $result = [];
  42. foreach ($data as $v) {
  43. $result[] = array_map('intval', explode('/', trim($v['path'] . $v['id'], '/')));
  44. }
  45. return $result;
  46. }
  47. public function getCityNameAttr($value, $data)
  48. {
  49. if (!$data['city_id']) return [];
  50. $city_id = explode('/', trim($data['city_id'],'/'));
  51. $result = app()->make(CityAreaRepository::class)->search([])->where('id','in',$city_id)->column('id,name');
  52. return $result;
  53. }
  54. public function setCityIdAttr($value)
  55. {
  56. return '/'.( implode('/',$value)).'/';
  57. }
  58. }