| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace app\common\model;
- class OrderModel extends BaseModel
- {
- protected $table = 'erp_order';
- protected function genSchema(array $schema)
- {
- // TODO: Implement genSchema() method.
- }
- public function genOrderNo($store_id, $store_abbr) {
- $order = $this->where('store_id', $store_id)->order('id','desc')->find();
- if(!$order)
- return "{$store_abbr}10000001";
- $code = (int)str_ireplace($store_abbr, '', $order->no) + 1;
- return "{$store_abbr}{$code}";
- }
- public function products() {
- return $this->hasMany(OrderProductModel::class, 'order_id','id')->where('is_delete',0);
- }
- public function payments() {
- return $this->hasMany(OrderPaymentModel::class, 'order_id','id')->where('is_delete',0);
- }
- public function annuals() {
- return $this->hasMany(OrderAnnualFeeModel::class, 'order_id','id')->where('is_delete',0);
- }
- public function proceeds() {
- return $this->hasMany(OrderProceedsModel::class, 'order_id','id')->where('is_delete',0);
- }
- public function store() {
- return $this->hasOne(StoreModel::class, 'id', 'store_id');
- }
- public function findByPaginate(array $params) {
- $where = [
- ['is_delete', '=', 0]
- ];
- if($params['store_id'] > 0)
- array_push($where,['store_id', '=', $params['store_id']]);
- if($params['type'] > 0)
- array_push($where,['type', '=', $params['type']]);
- return $this->where($where)
- ->with(['products','store'])
- ->order('create_time','desc')
- ->paginate(['list_rows'=>10, "query" => $params]);
- }
- public function report(array $params) {
- $where = [
- ['is_delete', '=', 0]
- ];
- if($params['store_id'] > 0)
- array_push($where,['store_id', '=', $params['store_id']]);
- if($params['type'] > 0)
- array_push($where,['type', '=', $params['type']]);
- return $this->where($where)
- ->with(['products','store'])
- ->order('create_time','desc')
- ->select();
- }
- public function findById($id)
- {
- return $this->where('is_delete',0)
- ->with([
- 'products',
- 'payments',
- 'payments.payment_channel',
- // 'payments.card_config',
- 'annuals',
- 'proceeds'
- ])->find($id);
- }
- }
|