OutsideOrder.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/1/13
  8. * Time: 15:29
  9. */
  10. namespace app\outside\modes;
  11. use app\common\models\BaseModel;
  12. use app\common\models\Order;
  13. use app\common\modules\order\OrderCollection;
  14. use app\common\services\CreateRandomNumber;
  15. /**
  16. * Class PreOutsideOrder
  17. * @property OrderCollection orders
  18. * @package app\outside\modules\order\models
  19. */
  20. class OutsideOrder extends BaseModel
  21. {
  22. protected $table = 'yz_outside_order_trade';
  23. static protected $needLog = true;
  24. protected $hidden = ['updated_at','deleted_at'];
  25. protected $guarded = [];
  26. public $attributes = [];
  27. protected $casts = ['order_ids' => 'json'];
  28. /**
  29. * 获取订单流水号
  30. * @return string
  31. */
  32. public static function createSn()
  33. {
  34. $paySN = CreateRandomNumber::sn('TN');
  35. while (1) {
  36. if (!self::where('trade_sn', $paySN)->first()) {
  37. break;
  38. }
  39. $paySN = CreateRandomNumber::sn('TN');
  40. }
  41. return $paySN;
  42. }
  43. /**
  44. * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
  45. */
  46. public function orders()
  47. {
  48. return $this->belongsToMany(Order::class, (new OutsideOrderHasManyOrder)->getTable(), 'outside_order_id', 'order_id');
  49. }
  50. }