WechatProfitSharingLog.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\framework\Database\Eloquent\Builder;
  11. /**
  12. * @property string transaction_id
  13. * @property string out_order_no
  14. * @property number amount
  15. * Class WechatProfitSharingLog
  16. * @package app\common\modules\wechat\models
  17. */
  18. class WechatProfitSharingLog extends BaseModel
  19. {
  20. public $table = 'yz_wechat_profit_sharing_log';
  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('hasOneWechatOrder', function ($q) use ($search) {
  29. $q->whereHas('hasOneOrder',function ($q2) use ($search) {
  30. $q2->where('order_sn', $search['order_sn']);
  31. });
  32. });
  33. }
  34. if ($search['status'] != '') {
  35. $query->where('status', $search['status']);
  36. }
  37. if ($search['is_time']) {
  38. $query->whereBetween('created_at', [strtotime($search['time']['start']), strtotime($search['time']['end'])]);
  39. }
  40. return $query;
  41. }
  42. public function hasOneWechatOrder()
  43. {
  44. return $this->hasOne(WechatPayOrder::class, 'transaction_id','transaction_id');
  45. }
  46. }