OrderVoucher.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\model;
  3. use app\common\service\SmsSend;
  4. use think\Model;
  5. /**
  6. * @property Orders orders
  7. * @property User user
  8. */
  9. class OrderVoucher extends Model
  10. {
  11. const PASS=1;
  12. const REJECT=2;
  13. protected $autoWriteTimestamp=true;
  14. public function orders(){
  15. return $this->belongsTo(Orders::class,'order_id');
  16. }
  17. public function user(){
  18. return $this->belongsTo(User::class);
  19. }
  20. public function makeAudit($pass,$remark=null){
  21. $this['status']=$pass?self::PASS:self::REJECT;
  22. $this['remark']=$remark;
  23. if($pass){
  24. $order=$this->orders;
  25. if($order->is_wait_pay){
  26. $order->makePay();
  27. }
  28. }
  29. #站内信
  30. SiteMsg::sendMsg(
  31. $pass?SiteMsg::TYPE_ORDER_OFFLINE_PAY_PASS:SiteMsg::TYPE_ORDER_OFFLINE_PAY_REJECT,
  32. $this->user,
  33. [
  34. 'order_no'=>$this->orders->order_no
  35. ]
  36. );
  37. #短信
  38. if(!$pass) {
  39. SmsSend::orderVoucherFail($this);
  40. }
  41. $this->save();
  42. }
  43. protected static function init()
  44. {
  45. self::beforeWrite(function (self $orderVoucher){
  46. if(empty($orderVoucher['image'])){
  47. $orderVoucher['image']=null;
  48. }
  49. });
  50. }
  51. }