| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?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('update_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);
- }
- /**
- * @param $params
- * @param bool $is_look_all
- * @return array
- * @throws \think\db\exception\DbException
- */
- public function search($params, $is_look_all = false) {
- $where = [
- ['is_delete', '=', 0],
- ['type', '=', $params['type']],
- ['store_id', '=', $params['store_id']],
- ];
- if (isset($params['order_no']) && strlen($params['order_no']) > 0)
- array_push($where, ['no', 'like', '%'.$params['order_no'].'%']);
- if (isset($params['start_time']) && $params['start_time'] > 0)
- array_push($where, ['create_time', '>=', $params['start_time']]);
- if (isset($params['end_time']) && $params['end_time'] > 0)
- array_push($where, ['create_time', '<=', $params['end_time']]);
- if (isset($params['obj_name']) && strlen($params['obj_name']) > 0)
- array_push($where, ['obj_names', 'like', '%'.$params['obj_name'].'%']);
- $query = $this->where($where)
- ->with(['products']);
- if (isset($params['advisor_id']))
- $query->where("FIND_IN_SET('{$params['advisor_id']}', advisor_ids)");
- if (!$is_look_all) {
- $query->where("FIND_IN_SET('{$params['admin_id']}', advisor_ids)");
- }
- return $query->order('update_time', 'desc')
- ->page($params['page'] ?? 1)
- ->paginate($params['size'] ?? 10)->toArray();
- }
- public function fetchOrderByCustomerId($c_id) {
- return $this->where([
- ['is_delete', '=', 0],
- ['customer_id', '=', $c_id]
- ])->select()->toArray();
- }
- /**
- * @param $customer_id
- * @param int $page
- * @param int $size
- * @return array
- * @throws \think\db\exception\DbException
- */
- public function fetchByCustomerId($customer_id, $page = 1, $size = 10) {
- return $this->where([
- ['is_delete', '=', 0],
- ['customer_id', '=', $customer_id]
- ])->with(['products'])->order('update_time', 'desc')->page($page)->paginate($size)->toArray();
- }
- }
|