Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

70 lignes
1.8 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zhengmingwei
  5. * Date: 2019-07-14
  6. * Time: 22:45
  7. */
  8. namespace app\admin\model\unishop;
  9. use think\Model;
  10. class DeliveryRule extends Model
  11. {
  12. // 表名
  13. protected $name = 'unishop_delivery_rule';
  14. // 自动写入时间戳字段
  15. protected $autoWriteTimestamp = 'int';
  16. // 定义时间戳字段名
  17. protected $createTime = 'createtime';
  18. protected $updateTime = 'updatetime';
  19. protected $append = ['area_content'];
  20. static $regionAll;
  21. static $regionTree;
  22. /**
  23. * 可配送区域
  24. * @param $value
  25. * @param $data
  26. * @return string
  27. */
  28. public function getAreaContentAttr($value, $data)
  29. {
  30. // 当前区域记录转换为数组
  31. $regionIds = explode(',', $data['area']);
  32. if (count($regionIds) === 373) return '全国';
  33. // 所有地区
  34. if (empty(self::$regionAll)) {
  35. self::$regionAll = Area::getCacheAll();
  36. self::$regionTree = Area::getCacheTree();
  37. }
  38. // 将当前可配送区域格式化为树状结构
  39. $alreadyTree = [];
  40. foreach ($regionIds as $regionId)
  41. $alreadyTree[self::$regionAll[$regionId]['pid']][] = $regionId;
  42. $str = '';
  43. foreach ($alreadyTree as $provinceId => $citys) {
  44. $str .= self::$regionTree[$provinceId]['name'];
  45. if (count($citys) !== count(self::$regionTree[$provinceId]['city'])) {
  46. $cityStr = '';
  47. foreach ($citys as $cityId)
  48. $cityStr .= self::$regionTree[$provinceId]['city'][$cityId]['name'];
  49. $str .= ' (<span class="am-link-muted">' . mb_substr($cityStr, 0, -1, 'utf-8') . '</span>)';
  50. }
  51. $str .= '、';
  52. }
  53. return mb_substr($str, 0, -1, 'utf-8');
  54. }
  55. }