FinancialRecordDao.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\common\dao\system\merchant;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\system\merchant\FinancialRecord;
  5. class FinancialRecordDao extends BaseDao
  6. {
  7. protected function getModel(): string
  8. {
  9. return FinancialRecord::class;
  10. }
  11. /**
  12. * @return string
  13. * @author zfy
  14. * @day 2020/6/9
  15. */
  16. public function getSn()
  17. {
  18. list($msec, $sec) = explode(' ', microtime());
  19. $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
  20. $orderId = 'jy' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
  21. return $orderId;
  22. }
  23. public function inc(array $data, $merId)
  24. {
  25. $data['mer_id'] = $merId;
  26. $data['financial_pm'] = 1;
  27. $data['financial_record_sn'] = $this->getSn();
  28. return $this->create($data);
  29. }
  30. public function dec(array $data, $merId)
  31. {
  32. $data['mer_id'] = $merId;
  33. $data['financial_pm'] = 0;
  34. $data['financial_record_sn'] = $this->getSn();
  35. return $this->create($data);
  36. }
  37. public function search(array $where)
  38. {
  39. $query = $this->getModel()::getDB()
  40. ->when(isset($where['financial_type']) && $where['financial_type'] !== '', function ($query) use ($where) {
  41. $query->whereIn('financial_type', $where['financial_type']);
  42. })
  43. ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  44. $query->where('mer_id', $where['mer_id']);
  45. })
  46. ->when(isset($where['user_info']) && $where['user_info'] !== '', function ($query) use ($where) {
  47. $query->where('user_info', $where['user_info']);
  48. })
  49. ->when(isset($where['user_id']) && $where['user_id'] !== '', function ($query) use ($where) {
  50. $query->where('user_id', $where['user_id']);
  51. })
  52. ->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  53. $query->whereLike('order_sn|user_info|financial_record_sn', "%{$where['keyword']}%");
  54. })
  55. ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  56. getModelTime($query, $where['date'], 'create_time');
  57. })
  58. ->when(isset($where['is_mer']) && $where['is_mer'] !== '', function ($query) use ($where) {
  59. if($where['is_mer']){
  60. $query->where('mer_id',$where['is_mer'])->where('type','in',[0,1]);
  61. }else{
  62. $query->where('type','in',[1,2]);
  63. }
  64. });
  65. return $query;
  66. }
  67. }