|
@@ -2,7 +2,9 @@
|
|
|
|
|
|
namespace app\common\model;
|
|
|
|
|
|
+use think\Db;
|
|
|
use think\Model;
|
|
|
+use time\DateHelper;
|
|
|
|
|
|
class Appointment extends Model
|
|
|
{
|
|
@@ -18,4 +20,54 @@ class Appointment extends Model
|
|
|
return $value ? date('Y-m-d', $value) : '';
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function createTicket()
|
|
|
+ {
|
|
|
+ if (!$this->ifExitsTicket()) {
|
|
|
+ $daylist = DateHelper::getDateList($this->start_time, $this->end_time);
|
|
|
+ foreach ($daylist as $datetime) {
|
|
|
+ (new AppointmentTicket())->save([
|
|
|
+ 'appointment_id' => $this->id,
|
|
|
+ 'appointment_daytime' => strtotime($datetime),
|
|
|
+ 'address_id' => $this->specialist->address_id
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $this->save(['ticket_status' => 1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function ifExitsTicket()
|
|
|
+ {
|
|
|
+ return $this->ticket_status > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function ifExitsAppointmentApplication()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 按地点获取预约列表
|
|
|
+ * @return false|\PDOStatement|string|\think\Collection
|
|
|
+ */
|
|
|
+ public static function listByAddress()
|
|
|
+ {
|
|
|
+
|
|
|
+ $all = (new Appointment())->where('end_time', '>', time())->select();
|
|
|
+
|
|
|
+ foreach ($all as $item) {
|
|
|
+ $item->createTicket();
|
|
|
+ }
|
|
|
+
|
|
|
+ $addressIds = (new AppointmentTicket())->where('appointment_daytime', '>=', strtotime(date('Y-m-d')))->distinct('true')->column('address_id');
|
|
|
+ return (new Address())->where('id', 'in', $addressIds)->select();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function specialist()
|
|
|
+ {
|
|
|
+ return $this->belongsTo('Specialist', 'provider_id');
|
|
|
+ }
|
|
|
}
|