StoreOrderProfitsharingDao.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\store\order;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\order\StoreOrderProfitsharing;
  14. class StoreOrderProfitsharingDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return StoreOrderProfitsharing::class;
  19. }
  20. public function getOrderSn()
  21. {
  22. list($msec, $sec) = explode(' ', microtime());
  23. $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
  24. $orderId = 'pr' . $msectime . random_int(10000, max(intval($msec * 10000) + 10000, 98369));
  25. return $orderId;
  26. }
  27. public function search(array $where)
  28. {
  29. return StoreOrderProfitsharing::getDB()->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  30. $query->where('mer_id', $where['mer_id']);
  31. })->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
  32. $query->where('order_id', $where['order_id']);
  33. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  34. $query->where('type', $where['type']);
  35. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  36. $query->where('status', $where['status']);
  37. })->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  38. getModelTime($query, $where['date']);
  39. })->when(isset($where['profit_date']) && $where['profit_date'] !== '', function ($query) use ($where) {
  40. getModelTime($query, $where['profit_date'], 'profitsharing_time');
  41. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  42. $query->whereLike('keyword', "%{$where['keyword']}%");
  43. });
  44. }
  45. public function getAutoProfitsharing($time)
  46. {
  47. return StoreOrderProfitsharing::getDB()->alias('A')->join('StoreOrder B', 'A.order_id = B.order_id', 'left')
  48. ->where(function ($query) {
  49. $query->where('B.status', '>', 1)->whereOr('B.status', -1);
  50. })->where('A.status', 0)->where(function ($query) use ($time) {
  51. $query->whereNotNull('B.verify_time')->where('B.verify_time', '<', $time);
  52. })->column('A.profitsharing_id');
  53. }
  54. }