StoreOrderProfitsharingDao.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\common\dao\store\order;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\store\order\StoreOrderProfitsharing;
  5. class StoreOrderProfitsharingDao extends BaseDao
  6. {
  7. protected function getModel(): string
  8. {
  9. return StoreOrderProfitsharing::class;
  10. }
  11. public function getOrderSn()
  12. {
  13. list($msec, $sec) = explode(' ', microtime());
  14. $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
  15. $orderId = 'pr' . $msectime . random_int(10000, max(intval($msec * 10000) + 10000, 98369));
  16. return $orderId;
  17. }
  18. public function search(array $where)
  19. {
  20. return StoreOrderProfitsharing::getDB()->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  21. $query->where('mer_id', $where['mer_id']);
  22. })->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
  23. $query->where('order_id', $where['order_id']);
  24. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  25. $query->where('type', $where['type']);
  26. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  27. $query->where('status', $where['status']);
  28. })->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  29. getModelTime($query, $where['date']);
  30. })->when(isset($where['profit_date']) && $where['profit_date'] !== '', function ($query) use ($where) {
  31. getModelTime($query, $where['profit_date'], 'profitsharing_time');
  32. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  33. $query->whereLike('keyword', "%{$where['keyword']}%");
  34. });
  35. }
  36. public function getAutoProfitsharing($time)
  37. {
  38. return StoreOrderProfitsharing::getDB()->alias('A')->join('StoreOrder B', 'A.order_id = B.order_id', 'left')
  39. ->where(function ($query) {
  40. $query->where('B.status', '>', 1)->whereOr('B.status', -1);
  41. })->where('A.status', 0)->where(function ($query) use ($time) {
  42. $query->whereNotNull('B.verify_time')->where('B.verify_time', '<', $time);
  43. })->column('A.profitsharing_id');
  44. }
  45. }