StoreService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\api\service;
  3. use addons\fastchat\library\Chat;
  4. use app\admin\model\Admin;
  5. use app\api\model\Store;
  6. class StoreService extends BaseService
  7. {
  8. private $model;
  9. public function __construct()
  10. {
  11. $this->model = new Store();
  12. }
  13. public function fetch(array $params)
  14. {
  15. $paginate = $this->model->fetch(
  16. $params['city_code'],
  17. isset($params['county_code']) ? $params['county_code'] : null,
  18. $params['lng_lat'],
  19. $params['service_id'] ?? null,
  20. $params['search_text'] ?? null,
  21. $params['distance'] ?? null,
  22. $params['page'] ?? 1,
  23. $params['size'] ?? 10
  24. );
  25. return [
  26. $paginate->items(),
  27. $paginate->total()
  28. ];
  29. }
  30. /**
  31. * @param array $params
  32. * @return \SResult
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. * @throws \think\exception\DbException
  36. */
  37. public function apply(array $params)
  38. {
  39. $store = $this->model->where("name", $params["name"])->find();
  40. if ($store) {
  41. return $this->fail("球房已经存在请勿重复申请");
  42. }
  43. $store_id = $this->model->insertGetId([
  44. "name" => $params["name"],
  45. "photo_images" => isset($params["photo_images"]) ? $params["photo_images"] : null,
  46. "description" => isset($params["description"]) ? $params["description"] : null,
  47. "tags" => isset($params["tags"]) ? $params["tags"] : null,
  48. "star" => 5,
  49. "phone" => $params["phone"],
  50. "area_city" => $params["area_city"],
  51. "p_code" =>$params["p_code"],
  52. "city_code" => $params["city_code"],
  53. "county_code" => $params["county_code"],
  54. "address" => $params["address"],
  55. "lng" => $params["lng"],
  56. "lat" => $params["lat"],
  57. "status" => \E_BASE_STATUS::Checking
  58. ]);
  59. $qr_code = \qrcodeBase64("https://pbh5.xunsoftware.com/pages/user/login", ["invite_store_id" => $store_id]);
  60. $this->model->update([
  61. "invite_qr_code" => $qr_code
  62. ], ["id" => $store_id]);
  63. return $this->ok(true);
  64. }
  65. public static function inform($no, $store_id, $city_code, $service_start_date)
  66. {
  67. $admins = Admin::whereOr("store_id", $store_id)
  68. ->whereOr("FIND_IN_SET('{$city_code}',city_codes)")->select();
  69. if (count($admins) > 0) {
  70. $admin_ids = join(",", array_map(function ($data) {
  71. return $data["id"];
  72. }, $admins));
  73. Chat::init(1)
  74. ->admin($admin_ids)
  75. ->send("球房有新订单,订单号为【{$no}】,预计到店时间为【{$service_start_date}】,请及时处理!");
  76. }
  77. }
  78. }