123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?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', 'product_type', 'total_amount', 'payment_type', 'payment_amount'])->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)]);
- }
- return true;
- }
- }
|