SystemStoreApply.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\models\system;
  3. use app\admin\model\system\SystemAdmin;
  4. use app\models\user\User;
  5. use crmeb\traits\ModelTrait;
  6. use crmeb\basic\BaseModel;
  7. /**
  8. * 门店自提 model
  9. * Class SystemStore
  10. * @package app\model\system
  11. */
  12. class SystemStoreApply extends BaseModel
  13. {
  14. use ModelTrait;
  15. /**
  16. * 数据表主键
  17. * @var string
  18. */
  19. protected $pk = 'id';
  20. /**
  21. * 模型名称
  22. * @var string
  23. */
  24. protected $name = 'system_store_apply';
  25. protected $append = [
  26. 'latlng'
  27. ];
  28. public static function getLatlngAttr($value, $data)
  29. {
  30. return $data['latitude'] . ',' . $data['longitude'];
  31. }
  32. /**
  33. * 获取门店列表
  34. * @param $where
  35. * @return array
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public static function getList($where)
  41. {
  42. $model = new self();
  43. if (isset($where['name']) && $where['name'] != '') {
  44. $model = $model->where('id|name|introduction', 'like', '%' . $where['name'] . '%');
  45. }
  46. if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
  47. $model = $model->where($data);
  48. }
  49. $count = $model->count();
  50. $data = $model->page((int)$where['page'], (int)$where['limit'])->select();
  51. foreach ($data as &$v) {
  52. $v['user'] = User::where('uid', $v['uid'])->value('nickname') . '/' . $v['uid'];
  53. }
  54. return compact('count', 'data');
  55. }
  56. /**
  57. * 获取连表查询条件
  58. * @param $type
  59. * @return array
  60. */
  61. public static function setData($type)
  62. {
  63. switch ((int)$type) {
  64. case 1:
  65. $data = ['status' => 0];
  66. break;
  67. case 2:
  68. $data = ['status' => 1];
  69. break;
  70. case 3:
  71. $data = ['status' => 2];
  72. break;
  73. };
  74. return isset($data) ? $data : [];
  75. }
  76. /**
  77. * 获取门店信息
  78. * @param int $id
  79. * @return array|\think\Model|null
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\DbException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. */
  84. public static function getDetail($id)
  85. {
  86. $storeInfo = self::where('id', $id)->find();
  87. $storeInfo['address'] = $storeInfo['address'] ? explode(',', $storeInfo['address']) : [];
  88. return $storeInfo;
  89. }
  90. }