OrderModel.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\common\model;
  3. class OrderModel extends BaseModel
  4. {
  5. protected $table = 'erp_order';
  6. protected function genSchema(array $schema)
  7. {
  8. // TODO: Implement genSchema() method.
  9. }
  10. public function genOrderNo($store_id, $store_abbr) {
  11. $order = $this->where('store_id', $store_id)->order('id','desc')->find();
  12. if(!$order)
  13. return "{$store_abbr}10000001";
  14. $code = (int)str_ireplace($store_abbr, '', $order->no) + 1;
  15. return "{$store_abbr}{$code}";
  16. }
  17. public function products() {
  18. return $this->hasMany(OrderProductModel::class, 'order_id','id')->where('is_delete',0);
  19. }
  20. public function payments() {
  21. return $this->hasMany(OrderPaymentModel::class, 'order_id','id')->where('is_delete',0);
  22. }
  23. public function annuals() {
  24. return $this->hasMany(OrderAnnualFeeModel::class, 'order_id','id')->where('is_delete',0);
  25. }
  26. public function proceeds() {
  27. return $this->hasMany(OrderProceedsModel::class, 'order_id','id')->where('is_delete',0);
  28. }
  29. public function store() {
  30. return $this->hasOne(StoreModel::class, 'id', 'store_id');
  31. }
  32. public function findByPaginate(array $params) {
  33. $where = [
  34. ['is_delete', '=', 0]
  35. ];
  36. if($params['store_id'] > 0)
  37. array_push($where,['store_id', '=', $params['store_id']]);
  38. if($params['type'] > 0)
  39. array_push($where,['type', '=', $params['type']]);
  40. return $this->where($where)
  41. ->with(['products','store'])
  42. ->order('create_time','desc')
  43. ->paginate(['list_rows'=>10, "query" => $params]);
  44. }
  45. public function report(array $params) {
  46. $where = [
  47. ['is_delete', '=', 0]
  48. ];
  49. if($params['store_id'] > 0)
  50. array_push($where,['store_id', '=', $params['store_id']]);
  51. if($params['type'] > 0)
  52. array_push($where,['type', '=', $params['type']]);
  53. return $this->where($where)
  54. ->with(['products','store'])
  55. ->order('create_time','desc')
  56. ->select();
  57. }
  58. public function findById($id)
  59. {
  60. return $this->where('is_delete',0)
  61. ->with([
  62. 'products',
  63. 'payments',
  64. 'payments.payment_channel',
  65. // 'payments.card_config',
  66. 'annuals',
  67. 'proceeds'
  68. ])->find($id);
  69. }
  70. }