1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zilongs
- * Date: 20-10-2
- * Time: 下午10:57
- */
- namespace App\Models;
- class OrderPack extends BaseModel
- {
- public function team()
- {
- return $this->belongsTo(Team::class);
- }
- public function order()
- {
- return $this->belongsTo(Order::class);
- }
- public function user(){
- return $this->belongsTo(User::class);
- }
- public static function checkUserServicePack($order_pack_id, $user_id, $product_type, $payment_amount)
- {
- $data = self::where('id', $order_pack_id)->where('user_id', $user_id)->first();
- if (empty($data)) {
- exit_out(null, 10001, '服务包不存在');
- }
- if ($data['end_time'] < time()) {
- exit_out(null, 10002, '服务包已过期');
- }
- if ($product_type == 1) {
- if ($data['phone_minutes'] < 10) {
- exit_out(null, 10003, '服务包的电话咨询时间不足');
- }
- }
- elseif ($product_type == 2) {
- if ($data['chat_num'] <= 0) {
- exit_out(null, 10004, '服务包的图文咨询次数不足');
- }
- }
- elseif ($product_type == 3) {
- if ($data['appoint_num'] <= 0) {
- exit_out(null, 10005, '服务包的门诊预约次数不足');
- }
- }
- elseif ($product_type == 4) {
- if ($data['vaccine_limit_amount'] < $payment_amount) {
- exit_out(null, 10006, '服务包疫苗金额不足');
- }
- }
- elseif ($product_type == 5) {
- if ($data['nurses_limit_amount'] < $payment_amount) {
- exit_out(null, 10007, '服务包儿保金额不足');
- }
- }
- return true;
- }
- public static function deductPackData($order_pack_id, $product_type, $payment_amount)
- {
- if ($product_type == 1) {
- self::where('id', $order_pack_id)->decrement('phone_minutes', 10);
- }
- elseif ($product_type == 2) {
- self::where('id', $order_pack_id)->decrement('chat_num');
- }
- elseif ($product_type == 3) {
- self::where('id', $order_pack_id)->decrement('appoint_num');
- }
- elseif ($product_type == 4) {
- self::where('id', $order_pack_id)->decrement('vaccine_limit_amount', $payment_amount);
- }
- elseif ($product_type == 5) {
- self::where('id', $order_pack_id)->decrement('nurses_limit_amount', $payment_amount);
- }
- return true;
- }
- }
|