TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], ], ], ]; } public function getDrugStoreDrug() { return $this->hasOne(DrugStoreDrug::class,['id'=>'drug_id']); } public function getDrug() { return $this->hasOne(Drug::class,['id'=>'drug_id']); } public function getProductOrder() { return $this->hasOne(ProductOrder::class,['id'=>'order_id']); } //关联门店 public function getStore() { return $this->hasOne(Store::class,['id'=>'store_id']); } //导出对账单 public static function inventory($params) { $su_id=\Yii::$app->user->id; //统计时间范围 if (!empty($params['date_max']) && !empty($params['date_min'])) { $params['date_max'] = strtotime($params['date_max']); $params['date_min'] = strtotime($params['date_min']); } else{ $date_max = date('Y-m-d'); $date_min = date('Y-m-d',strtotime("-31 day")); } $data = [ 'and', ['between', 'created_at', $params['date_min'], $params['date_max']], ['status' => $params['status']], ]; //查询数据 $list=Reconciliation::find()->filterWhere($data)->with(['productOrder','drug','store'])->asArray()->all(); //把结果按照显示顺序存到返回的数组中 if(!empty($list)){ foreach ($list as $key => $value){ $inventory[$key]['drug_name'] = $value['drug']['drug_name']; $inventory[$key]['drug_number'] = $value['drug']['drug_number']??'无'; $inventory[$key]['store'] = $value['store']['name']; $inventory[$key]['number'] = $value['number']; $inventory[$key]['total_buy_price'] = $value['total_buy_price']; $inventory[$key]['total_price'] = $value['total_price']; $inventory[$key]['pay_time'] = date('Y-m-d H:i:s',$value['pay_time'])??'暂无'; } }else{ $inventory[0]['prescription_no']= '无数据导出'; } return $inventory; } }