123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\common\model;
- use app\common\service\SmsSend;
- use think\Model;
- /**
- * @property Orders orders
- * @property User user
- */
- class OrderVoucher extends Model
- {
- const PASS=1;
- const REJECT=2;
- protected $autoWriteTimestamp=true;
- public function orders(){
- return $this->belongsTo(Orders::class,'order_id');
- }
- public function user(){
- return $this->belongsTo(User::class);
- }
- public function makeAudit($pass,$remark=null){
- $this['status']=$pass?self::PASS:self::REJECT;
- $this['remark']=$remark;
- if($pass){
- $order=$this->orders;
- if($order->is_wait_pay){
- $order->makePay();
- }
- }
- #站内信
- SiteMsg::sendMsg(
- $pass?SiteMsg::TYPE_ORDER_OFFLINE_PAY_PASS:SiteMsg::TYPE_ORDER_OFFLINE_PAY_REJECT,
- $this->user,
- [
- 'order_no'=>$this->orders->order_no
- ]
- );
- #短信
- if(!$pass) {
- SmsSend::orderVoucherFail($this);
- }
- $this->save();
- }
- protected static function init()
- {
- self::beforeWrite(function (self $orderVoucher){
- if(empty($orderVoucher['image'])){
- $orderVoucher['image']=null;
- }
- });
- }
- }
|