113 lines
3.4 KiB
PHP
113 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace common\models;
|
|
|
|
use yii\behaviors\TimestampBehavior;
|
|
use yii\db\ActiveRecord;
|
|
|
|
class FundWater extends \common\modelsgii\FundWater
|
|
{
|
|
public function behaviors()
|
|
{
|
|
return [
|
|
[
|
|
'class' => TimestampBehavior::class,
|
|
'attributes' => [
|
|
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'],
|
|
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
//挂号
|
|
public function getRegister()
|
|
{
|
|
return $this->hasOne(Register::class,['id'=>'order_id']);
|
|
}
|
|
//产品订单
|
|
public function getProductOrder()
|
|
{
|
|
return $this->hasOne(ProductOrder::class,['id'=>'order_id']);
|
|
}
|
|
|
|
//诊所
|
|
public function getStore()
|
|
{
|
|
return $this->hasOne(Store::class,['id'=>'store_id']);
|
|
}
|
|
|
|
|
|
//医生
|
|
public function getDoctor()
|
|
{
|
|
return $this->hasOne(DoctorInfo::class,['su_id'=>'service_user_id']);
|
|
}
|
|
|
|
//用户
|
|
public function getUser()
|
|
{
|
|
return $this->hasOne(User::class,['id'=>'user_id']);
|
|
}
|
|
|
|
//导出资金流水
|
|
public static function inventory($params,$store_id)
|
|
{
|
|
$where = $andWhere = [];
|
|
//统计时间范围
|
|
if (!empty($params['start_time']) && !empty($params['end_time'])) {
|
|
$start_time=strtotime($params['start_time']);
|
|
$end_time=strtotime($params['end_time']);
|
|
$andWhere = ['between', 'yii_fund_water.created_at', $start_time, $end_time];
|
|
}
|
|
|
|
if($store_id){
|
|
$where['yii_fund_water.store_id'] = $store_id;
|
|
}
|
|
// $where['is_deleted'] = 0
|
|
if (!empty($params['order_no'])) {//订单号
|
|
$where['yii_fund_water.order_no'] = $params['order_no'];
|
|
}
|
|
if (!empty($params['refund_no'])) {//退款单号
|
|
$where['yii_fund_water.refund_no'] = $params['refund_no'];
|
|
}
|
|
$name = $params['store'];
|
|
if($name){
|
|
$where['yii_store.name'] = $name;
|
|
}
|
|
$doctor = $params['doctor'];
|
|
if($doctor){
|
|
$where['yii_doctor_info.name'] = $doctor;
|
|
}
|
|
//查询数据
|
|
$list=FundWater::find()->where($where)->andWhere($andWhere)->joinWith(['doctor','user','store'])->asArray()->all();
|
|
|
|
//把结果按照显示顺序存到返回的数组中
|
|
if(!empty($list)){
|
|
foreach ($list as $key => $value){
|
|
|
|
//订单类型
|
|
if ($value['order_type']==1){
|
|
$inventory[$key]['order_type'] ='产品订单';
|
|
}elseif ($value['order_type']==2){
|
|
$inventory[$key]['order_type'] ='挂号订单';
|
|
}elseif ($value['order_type']==3){
|
|
$inventory[$key]['order_type'] ='问诊订单';
|
|
}else{
|
|
$inventory[$key]['order_type'] ='暂无';
|
|
}
|
|
|
|
$inventory[$key]['doctor'] = $value['doctor']['name']??'无';
|
|
$inventory[$key]['patient'] = $value['user']['nickname']??'无';
|
|
|
|
$inventory[$key]['price'] = $value['price']??'无';
|
|
$inventory[$key]['store'] = $value['store']['name']??'无';//
|
|
$inventory[$key]['created_at'] = date('Y-m-d H:i:s',$value['created_at']);//下单时间
|
|
}
|
|
|
|
}else{
|
|
$inventory[0]['prescription_no']= '无数据导出';
|
|
}
|
|
return $inventory;
|
|
}
|
|
} |