WechatPayOrder.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yunzhong
  5. * Date: 2019/11/28
  6. * Time: 16:44
  7. */
  8. namespace app\common\modules\wechat\models;
  9. use app\common\models\BaseModel;
  10. use app\common\models\Order;
  11. /**
  12. * @property int account_id
  13. * @property boolean profit_sharing
  14. * @property string transaction_id
  15. * Class WechatPayOrder
  16. * @package app\common\modules\wechat\models
  17. */
  18. class WechatPayOrder extends BaseModel
  19. {
  20. public $table = 'yz_wechat_pay_order';
  21. public $guarded = [''];
  22. public function scopeSearch($query, $search)
  23. {
  24. if ($search['transaction_id']) {
  25. $query->where('transaction_id', $search['transaction_id']);
  26. }
  27. if ($search['order_sn']) {
  28. $query->whereHas('hasOneOrder',function ($q2) use ($search) {
  29. $q2->where('order_sn', $search['order_sn']);
  30. });
  31. }
  32. if ($search['profit_sharing'] != '') {
  33. $query->where('profit_sharing', $search['profit_sharing']);
  34. }
  35. if ($search['is_time']) {
  36. $query->whereBetween('created_at', [strtotime($search['time']['start']), strtotime($search['time']['end'])]);
  37. }
  38. return $query;
  39. }
  40. public function hasOneOrder()
  41. {
  42. return $this->hasOne(Order::class,'id','order_id');
  43. }
  44. }