Address.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\store\model\store;
  13. use app\common\model\store\Address as StoreAddressModel;
  14. /**
  15. * 商家地址模型
  16. * Class Address
  17. * @package app\store\model
  18. */
  19. class Address extends StoreAddressModel
  20. {
  21. /**
  22. * 获取列表
  23. * @param array $param
  24. * @return \think\Paginator
  25. * @throws \think\db\exception\DbException
  26. */
  27. public function getList(array $param = [])
  28. {
  29. return $this->where($this->getFilter($param))
  30. ->where('is_delete', '=', 0)
  31. ->order(['sort', $this->getPk()])
  32. ->paginate(15);
  33. }
  34. /**
  35. * 获取全部记录
  36. * @param array $param
  37. * @return \think\Collection
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. */
  42. public function getAll(array $param = [])
  43. {
  44. return $this->where($this->getFilter($param))
  45. ->where('is_delete', '=', 0)
  46. ->order(['sort', $this->getPk()])
  47. ->select();
  48. }
  49. /**
  50. * 根据param检索查询条件
  51. * @param array $param
  52. * @return array
  53. */
  54. private function getFilter(array $param = [])
  55. {
  56. // 默认查询条件
  57. $params = $this->setQueryDefaultValue($param, [
  58. 'type' => 0, // 地址类型(10发货地址 20退货地址)
  59. 'search' => '', // 收货人姓名/联系电话
  60. ]);
  61. // 检索查询条件
  62. $filter = [];
  63. $params['type'] > 0 && $filter[] = ['type', '=', $params['type']];
  64. !empty($params['search']) && $filter[] = ['name|phone', 'like', "%{$params['search']}%"];
  65. return $filter;
  66. }
  67. /**
  68. * 添加新记录
  69. * @param array $data
  70. * @return false|int
  71. */
  72. public function add(array $data)
  73. {
  74. list($data['province_id'], $data['city_id'], $data['region_id']) = $data['cascader'];
  75. $data['store_id'] = self::$storeId;
  76. return $this->save($data);
  77. }
  78. /**
  79. * 编辑记录
  80. * @param array $data
  81. * @return bool|int
  82. */
  83. public function edit(array $data)
  84. {
  85. list($data['province_id'], $data['city_id'], $data['region_id']) = $data['cascader'];
  86. return $this->save($data);
  87. }
  88. /**
  89. * 删除记录
  90. * @return bool|int
  91. */
  92. public function remove()
  93. {
  94. return $this->save(['is_delete' => 1]);
  95. }
  96. }