12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zilongs
- * Date: 20-9-30
- * Time: 下午10:56
- */
- namespace App\Models;
- class Order extends BaseModel
- {
- CONST UNPAID = 1, ISING = 2, FINISHED = 3,CANCELED=4; //订单状态(1.未支付 2.进行中 3.已完成 4.已取消)
- public static $_order_status = [
- self::UNPAID=>'未支付',
- self::ISING=>'进行中',
- self::FINISHED=>'已完成',
- self::CANCELED=>'已取消',
- ];
- //获取订单状态
- public function getStatus()
- {
- return self::$_order_status;
- }
- public function docter()
- {
- return $this->belongsTo(Docter::class);
- }
- public function orderPatient()
- {
- return $this->hasOne(OrderPatient::class);
- }
- public function orderPack()
- {
- return $this->hasMany(OrderPack::class);
- }
- public function orderNurse()
- {
- return $this->hasMany(OrderNurse::class);
- }
- public function orderVaccine()
- {
- return $this->hasOne(OrderVaccine::class);
- }
- public function orderUser()
- {
- return $this->hasOne(User::class,'id','user_id');
- }
- public function organization()
- {
- return $this->belongsTo(Organization::class);
- }
- //支付完成的处理方法
- public static function payCompletedHandle($order_id)
- {
- $order = Order::select(['user_id', 'docter_id', 'product_type', 'total_amount', 'payment_type', 'payment_amount', 'order_sn'])->where('id', $order_id)->first();
- //发送下单消息
- if ($order['product_type'] < 6) {
- $product_type_text = config('config.product_type_map')[$order['product_type']];
- UserMessage::saveMessage($order['user_id'], 4, $order_id, [$product_type_text]);
- }
- elseif ($order['product_type'] == 6) {
- $orderPack = OrderPack::select(['pack_name', 'end_time'])->where('order_id', $order_id)->first();
- UserMessage::saveMessage($order['user_id'], 5, $order_id, [$orderPack['pack_name'], date('Y-m-d', $orderPack['end_time'])]);
- }
- elseif ($order['product_type'] == 7) {
- $user = User::select(['balance'])->where('id', $order['user_id'])->first();
- UserMessage::saveMessage($order['user_id'], 7, $order_id, [round($order['total_amount']/100, 2), round($user['balance']/100, 2)]);
- }
- //发送余额付款成功消息
- if ($order['payment_type'] == 2) {
- $user = User::select(['balance'])->where('id', $order['user_id'])->first();
- UserMessage::saveMessage($order['user_id'], 8, $order_id, [round($order['payment_amount']/100, 2), round($user['balance']/100, 2)]);
- }
- //发送医生端消息
- DocterMessage::saveMessage($order['docter_id'], $order['user_id'], 1, $order_id, [$order['order_sn']]);
- return true;
- }
- public function suggest()
- {
- return $this->hasOne(Suggest::class)->select(['id', 'order_id']);
- }
- }
|