Income.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. *
  5. * User: king/QQ:995265288
  6. * Date: 2018/5/15 上午10:00
  7. * Email: livsyitian@163.com
  8. */
  9. namespace app\backend\modules\income\models;
  10. use app\common\scopes\UniacidScope;
  11. class Income extends \app\common\models\Income
  12. {
  13. public static function boot()
  14. {
  15. parent::boot();
  16. self::addGlobalScope( new UniacidScope);
  17. }
  18. public function scopeRecords($query)
  19. {
  20. return $query;
  21. }
  22. public function scopeWithMember($query)
  23. {
  24. return $query->with(['member' => function($query) {
  25. return $query->select('uid', 'nickname', 'realname', 'avatar', 'mobile');
  26. }]);
  27. }
  28. public function scopeSearch($query, $search)
  29. {
  30. if ($search['class']) {
  31. //门店预约中途换了关联模型,兼容新旧记录
  32. if($search['class']=='Yunshop\Appointment\common\models\AppointmentOrderService'){
  33. $query->whereIn('incometable_type', [$search['class'],'Yunshop\Appointment\common\models\AppointmentIncome']);
  34. }else{
  35. $query->where('incometable_type', $search['class']);
  36. }
  37. }
  38. if ($search['status'] || $search['status'] == '0') {
  39. $query->where('status', $search['status']);
  40. }
  41. if ($search['pay_status'] || $search['pay_status'] == '0') {
  42. $query->where('pay_status', $search['pay_status']);
  43. }
  44. if (Is_numeric($search['time']['start']) && Is_numeric($search['time']['end'])) {
  45. $query = $query->whereBetween('created_at', [$search['time']['start'] / 1000, $search['time']['end'] / 1000]);
  46. }
  47. return $query;
  48. }
  49. public function scopeSearchMember($query, $search)
  50. {
  51. if ($search['member_id'] || $search['realname']) {
  52. $query->whereHas('member', function($query)use($search) {
  53. if ($search['realname']) {
  54. $query->select('uid', 'nickname','realname','mobile','avatar')
  55. ->where('realname', 'like', '%' . $search['realname'] . '%')
  56. ->orWhere('mobile', 'like', '%' . $search['realname'] . '%')
  57. ->orWhere('nickname', 'like', '%' . $search['realname'] . '%');
  58. }
  59. if ($search['member_id']) {
  60. $query->whereUid($search['member_id']);
  61. }
  62. });
  63. }
  64. return $query;
  65. }
  66. }