WechatWithdrawLog.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\common\models;
  3. use app\common\traits\CreateOrderSnTrait;
  4. use Illuminate\Database\Eloquent\Builder;
  5. /**
  6. * Class WechatWithdrawLog
  7. * @package app\common\models
  8. * @property int uniacid
  9. * @property string withdraw_sn
  10. * @property int member_id
  11. * @property string out_batch_no
  12. * @property string out_detail_no
  13. * @property string batch_id
  14. * @property string batch_status
  15. * @property string detail_id
  16. * @property string detail_status
  17. * @property string http_code
  18. * @property string fail_code
  19. * @property string fail_msg
  20. * @property int status
  21. * @property int type
  22. * @property int pay_type
  23. * @method static self search(array $search=[],array $select = ['*'])
  24. */
  25. class WechatWithdrawLog extends BaseModel
  26. {
  27. use CreateOrderSnTrait;
  28. protected $table = 'yz_wechat_withdraw_log';
  29. public $timestamps = true;
  30. protected $guarded = [];
  31. protected $appends = [];
  32. /**
  33. * 需要重试的状态
  34. */
  35. const REPEAT_STATUS = [
  36. 'SYSTEM_ERROR','NOT_ENOUGH','FREQUENCY_LIMITED'
  37. ];
  38. /**
  39. * @param $fill
  40. * @return WechatWithdrawLog
  41. * @throws \Exception
  42. */
  43. public static function saveLog($fill = [])
  44. {
  45. $model = new self();
  46. $model->fill($fill);
  47. if (!$model->save()) {
  48. throw new \Exception('保存记录失败');
  49. }
  50. return $model;
  51. }
  52. public static function updateModel(WechatWithdrawLog $log,$update = [])
  53. {
  54. if (!$update) {
  55. throw new \Exception('修改数据为空');
  56. }
  57. $log->update($update);
  58. }
  59. /**
  60. * @param Builder $query
  61. * @param array $search
  62. * @param array $select
  63. * @return Builder
  64. */
  65. public function scopeSearch(Builder $query, $search = [] , $select = ['*'])
  66. {
  67. $query = $query->select($select);
  68. if ($search['id']) {
  69. $query = $query->where('id',$search['id']);
  70. }
  71. if ($search['withdraw_sn']) {
  72. $query = $query->where('withdraw_sn',$search['withdraw_sn']);
  73. }
  74. if ($search['out_batch_no']) {
  75. $query = $query->where('out_batch_no',$search['out_batch_no']);
  76. }
  77. if ($search['member_id']) {
  78. $query = $query->where('member_id',$search['member_id']);
  79. }
  80. if (isset($search['status']) && is_numeric($search['status'])) {
  81. $query = $query->where('status',$search['status']);
  82. }
  83. if ($search['many_status']) {
  84. $query = $query->whereIn('status',$search['many_status']);
  85. }
  86. if (isset($search['type']) && is_numeric($search['type'])) {
  87. $query = $query->where('type',$search['type']);
  88. }
  89. return $query;
  90. }
  91. }