初始化仓库

This commit is contained in:
2024-09-19 11:32:39 +08:00
commit 8f5315e936
921 changed files with 76455 additions and 0 deletions

View File

@@ -0,0 +1,144 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use admin\models\forms\drug\ArticleForm;
use common\models\Categories;
use common\models\DoctorArticle;
use yii\db\Exception;
class ArticleController extends BaseAdminController
{
/**
* @doc-name 新增或编辑文章分类
* @doc-param int id 传id则修改 / optional
* @doc-param string name 分类
* @doc-param int pid 父级id
* @doc-param int level 级别
*/
public function actionSaveCategories()
{
$post=\Yii::$app->request->post();
$this->requestValidate($post,[
[['name','pid','level'],'required'],
]);
if (empty($post['id'])){
$Categories= Categories::find()->where(['name'=>$post['name'],'is_deleted'=>0])->one();
if (!$Categories){
$Categories= new Categories();
$Categories->name=$post['name'];
$Categories->pid=$post['pid'];
$Categories->level=$post['level'];
$Categories->save();
}
return ['已添加'];
}else{
$Categories= Categories::find()->where(['id'=>$post['id'],'is_deleted'=>0])->one();
if (!$Categories){
throw new Exception('分类不存在');
}
$Categories->name=$post['name']??$Categories->name;
$Categories->pid=$post['pid']??$Categories->pid;;
$Categories->level=$post['level']??$Categories->level;;
if (! $Categories->saveOrFail()){
throw new Exception('编辑失败');
};
return ['编辑成功'];
}
}
/**
* @doc-name 删除分类
* @doc-param int id ID
*/
public function actionDelCategories()
{
$get=\Yii::$app->request->get();
$this->requestValidate($get,[
['id','required'],
]);
$Categories= Categories::find()->where(['id'=>$get['id']])->one();
if (!$Categories){
throw new Exception('分类不存在');
}
$Categories->is_deleted=1;
if (!$Categories->saveOrFail()){
throw new Exception('删除失败');
};
return ['删除成功'];
}
/**
* @doc-name 文章分类列表
* @doc-return mixed @List{id,name-string-分类,pid-int-父级id,level-int-级别} 文章分类列表
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionCategoriesList()
{
$get=\Yii::$app->request->get();
$query= Categories::find()->where(['is_deleted'=>0])->orderBy(['id'=>SORT_DESC]);
$this->field=[
Categories::class=>[
'id','name','pid','level'
]
];
return $this->create($query,$get);
}
/**
* @doc-name 文章列表
* @doc-return mixed @List{id,su_id-int-医生id 0为后台发布,cover-string-封面,title-string-文章标题,intro-string-简介,content-string-内容,video_url-string-视频链接,read_num-int-阅读量,collection-string-货收藏),is_draft-int-是否是草稿0否1是} 文章列表
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionArticleList()
{
$get=\Yii::$app->request->get();
$query= DoctorArticle::find()->where(['is_delete'=>0])->orderBy(['id'=>SORT_DESC]);
$this->field=[
DoctorArticle::class=>[
'id','cid','su_id','cover','title','intro','content','video_url','read_num','collection','is_draft','categories'=>'categories.name','type'
]
];
return $this->create($query,$get);
}
/**
* @doc-name 新增或修改文章
* @doc-param int id 传id则修改 / optional
* @doc-param int type 文章类型1图文类型2图片 / optional
* @doc-param int cid 分类id / optional
* @doc-param int su_id 发部人 / optional
* @doc-param string cover 封面
* @doc-param string title 标题
* @doc-param string intro 简介 / optional
* @doc-param string content 内容
* @doc-param string video_url 视频链接 / optional
* @doc-param int is_draft 是否是草稿0否1是 / optional
*/
public function actionSaveArticle()
{
$post = \Yii::$app->request->post();
$ArticleForm= new ArticleForm();
$ArticleForm->attributes = $post;
return $ArticleForm->save();
}
/**
* @doc-name 删除文章
* @doc-param int id id
*/
public function actionDelArticle()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get,[
['id','required'],
]);
$ArticleForm= new ArticleForm();
$ArticleForm->attributes = $get;
return $ArticleForm->del();
}
}

View File

@@ -0,0 +1,216 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use admin\models\forms\drug\DepartForm;
use common\enums\UserRoleEnum;
use common\helpers\ArrayHelper;
use common\models\Department;
use common\models\Platform;
use common\models\Store;
/**
* @doc-module 科室与门店
*/
class DepartController extends BaseAdminController
{
/**
* @doc-name 科室列表(处理成二维数组)
* @doc-param int name 科室名字 / optional
* @doc-return mixed @List{id,name-string-名字,pid-int-父级id,level-int-等级,child_depart-string-子级科室} 科室信息
*/
public function actionDeptList()
{
$get = \Yii::$app->request->get();
$query = Department::find();
if (!empty($get['name'])) {
$query->andWhere([
'like', 'name', $get['name']
]);
}
$this->field = [
Department::class => [
'id', 'name', 'pid', 'level',
'child_depart' => 'child'
]
];
return $this->create($query, $get);
}
/**
* @doc-name 科室列表
* @doc-param int name 科室名字 / optional
* @doc-return mixed @List{id,name-string-名字,pid-int-父级id,level-int-等级} 科室信息
*/
public function actionList()
{
$get = \Yii::$app->request->get();
$query = Department::find();
if (!empty($get['name'])) {
$query->andWhere([
'like', 'name', $get['name']
]);
}
return $query->select(['id', 'name', 'level'])->all();
}
/**
* @doc-name 新增科室
* @doc-param string name 科室
* @doc-param int level 科室级别
* @doc-param int pid 父级id / optional
* @doc-param string is_recommend 是否推荐 / optional
* @doc-param int feature 是否是重点特色专科0不是1是 / optional
*/
public function actionSaveDept()
{
$post = \Yii::$app->request->post();
$DepartForm = new DepartForm();
$DepartForm->attributes = $post;
return $DepartForm->SaveDepart();
}
/**
* @doc-name 门店列表
* @doc-param int name 名字 / optional
* @doc-param string region 省 / optional
* @doc-param string city 市 / optional
* @doc-param int limit 每页条数 / optional
* @doc-return mixed @List{id,name-string-名字,drugstore_id-int-仓库id,drugstore-string-仓库,plate_id-int-平台id,position-string-位置,pic-string-图片,contact-string-联系人,mobile-string-联系电话,qr_code-string-门店二维码,start_time-string-开始营业时间,end_time-string-结束营业时间,see_rate-int-是否查看毛利率0否1是} 门店信息
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionStoreList()
{
$get = \Yii::$app->request->get();
$query = Store::find()->alias('s');
$name = \Yii::$app->request->get('name');
$region = \Yii::$app->request->get('region');
$city = \Yii::$app->request->get('city');
$admin = \Yii::$app->user->identity;
if ($admin->role==UserRoleEnum::STORE_ADMIN){
$query->andWhere(['s.id'=>$admin->store_id])->orderBy(['s.id'=>SORT_DESC]);
}elseif ($admin->role==UserRoleEnum::PROVINCE_DAI){
$query->andWhere(['s.province_id'=>$admin->province_id])->orderBy(['s.id'=>SORT_DESC]);
}elseif ($admin->role==UserRoleEnum::CITY_DAI){
$query->andWhere(['s.city_id'=>$admin->city_id])->orderBy(['s.id'=>SORT_DESC]);
}elseif ($admin->role==UserRoleEnum::SUPPLY){
$query->andWhere(['s.code'=>$admin->code])->orderBy(['s.id'=>SORT_DESC]);
}else{
$query->orderBy(['s.id'=>SORT_DESC]);
}
if (!empty($name) ) {
$query->andWhere([
'or',
['like', 's.name', $name],
['like', 's.shouzimu', $name],
]);
}
if ( !empty($region)) {
$query->joinWith(['province'=>function($p)use($region){
$p->alias('p');
$p->where(['like','p.name',$region]);
}]);
}
if ( !empty($city)) {
$query->joinWith(['city'=>function($p)use($city){
$p->alias('c');
$p->where(['like','c.name',$city]);
}]);
}
$this->field = [
Store::class => [
'id', 'plate_id', 'name', 'position', 'offical_seal', 'pic', 'contact', 'mobile', 'qr_code',
'start_time', 'end_time',
'drugstore_id', 'see_rate',
'drugstore' => 'drugStore.name',
'code','uid','supply'=>'admin.username',
'province'=>'province.name',
'city'=>'city.name',
'province_id',
'city_id','erp_id'
]
];
return $this->create($query, $get);
}
/**
* @doc-name 新增或编辑门店
* @doc-desc 传id则修改
* @doc-param int id 门店id / optional
* @doc-param int plate_id 平台ID
* @doc-param int erp_id erp_id / optional
* @doc-param int drugstore_id 仓库ID
* @doc-param string name 名字
* @doc-param string contact 联系人
* @doc-param string position 位置
* @doc-param string mobile 电话
* @doc-param int province_id 省
* @doc-param int city_id 市
* @doc-param string code 推广码
* @doc-param string offical_seal 公章
* @doc-param string start_time 开始营业时间
* @doc-param string end_time 结束营业时间
* @doc-param string pic 图片 / optional
* @doc-param string bank_user_name 开户人姓名 / optional
* @doc-param string bank_card 银行卡号 / optional
* @doc-param string bank_name 开户行 / optional
* @doc-param int bank_account_type 银行账户类型 1:对公,2:对私,5:存折 / optional
* @doc-param string bank_no 银行联行号bank_account_type=1或5或非62开头的对私银行账户时必选 / optional
*/
public function actionSaveStore()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
['code','required','message'=>'推广码不能为空'],
['plate_id','required','message'=>'平台ID不能为空'],
['drugstore_id','required','message'=>'仓库ID不能为空'],
['name','required','message'=>'名字不能为空'],
['contact','required','message'=>'联系人不能为空'],
['position','required','message'=>'联系人不能为空'],
['mobile','required','message'=>'电话不能为空'],
// ['offical_seal','required','message'=>'公章不能为空'],
['start_time','required','message'=>'开始营业时间不能为空'],
['end_time','required','message'=>'结束营业时间不能为空'],
['province_id','required','message'=>'省份不能为空'],
['city_id','required','message'=>'城市不能为空'],
]);
$post['store_name'] = $post['name'];
$post['shouzimu']=ArrayHelper::shouzimu($post['name']);
$DepartForm = new DepartForm();
$DepartForm->attributes = $post;
return $DepartForm->SaveStore();
}
/**
* @doc-name 平台列表
* @doc-param int name 名字 / optional
* @doc-return mixed @List{id,name-string-平台名称,token-string-平台密钥(后期使用),url-string-通讯地址,callbackurl-string-位置,status-int-1使用0不使用} 平台信息
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionPlatformList()
{
$get = \Yii::$app->request->get();
$query = Platform::find();
if (!empty($get['name'])) {
$query->andWhere([
'like', 'name', $get['name']
]);
}
$this->field = [
Platform::class => [
'id', 'name', 'token', 'callbackurl', 'url', 'status'
]
];
return $this->create($query, $get);
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use admin\models\forms\drug\DiagnoseForm;
use common\modelsgii\Disease;
use moonland\phpexcel\Excel;
use yii\db\Exception;
use yii\web\UploadedFile;
/**
* @doc-module 诊断症状
*/
class DiagnoseController extends BaseAdminController
{
/**
* @doc-name 诊断症状列表
* @doc-param string name 名称 / optional
* @doc-param string major_number 主编号 / optional
* @doc-param string ref_number 次编号 / optional
*/
public function actionList()
{
$get = \Yii::$app->request->get();
$query = Disease::find()->where(['is_delete' => 0]);
if (!empty($get['name'])){
$query->andWhere([
'like', 'name',$get['name']
]);
}
if (!empty($get['major_number'])){
$query->andWhere([
'major_number'=>$get['major_number']
]);
}
if (!empty($get['ref_number'])){
$query->andWhere([
'ref_number'=>$get['ref_number']
]);
}
$this->field = [
Disease::class => [
'id', 'diagnose_code','name', 'major_number', 'ref_number'
]
];
return $this->create($query, $get);
}
/**
* @doc-name 新增或编辑诊断症状
* @doc-desc 传ID则编辑
* @doc-param int ID 症状id / optional
* @doc-param string name 名字
* @doc-param string diagnose_code 疾病诊断代码 / optional
* @doc-param string major_number 主编号 / optional
* @doc-param string ref_number 次编号 / optional
*/
public function actionSave()
{
$post = \Yii::$app->request->post();
$DiagnoseForm = new DiagnoseForm();
$DiagnoseForm->attributes = $post;
return $DiagnoseForm->save();
}
/**
* @doc-name 删除诊断症状
* @doc-param int id 诊断症状ID
*/
public function actionDel()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
['id', 'required']
]);
$DiagnoseForm = new DiagnoseForm();
$DiagnoseForm->attributes = $post;
return $DiagnoseForm->del();
}
/**
* @doc-name 导入诊断症状
* @doc-param file file 文件
*/
public function actionImport()
{
$request = \Yii::$app->request;
if ($request->isPost) {
//设置最大执行时间
ini_set("max_execution_time", "360");
$file = UploadedFile::getInstanceByName('file');
if ($file->size > 5 * 1024 * 1024) {
throw new Exception('excel文件不能超过5M!');
}
//文件名
$filename = date('His') . md5($file->getBaseName()) . mt_rand(1000, 9999) . '.' . $file->getExtension();
//保存文件
$file->saveAs($filename);
$data = Excel::import($filename, [
'setFirstRecordAsKeys' => true,
'getOnlySheet' => 'Sheet1',
]);
$DiagnoseForm = new DiagnoseForm();
return $DiagnoseForm->export($data);
} else {
throw new Exception('请求方式错误');
}
}
}

View File

@@ -0,0 +1,916 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use admin\models\Admin;
use common\enums\UserRoleEnum;
use common\helpers\FuncHelper;
use common\models\CashAccount;
use common\models\CashApply;
use common\models\Ledger;
use common\models\LedgerLog;
use common\models\Log;
use common\models\Register;
use common\models\Store;
use common\modelsgii\ProductOrder;
use common\services\EplPayService;
use yii\base\Exception;
use yii\helpers\Json;
use yii\web\Response;
use common\services\ExportService;
/**
* @doc-module 分账
*/
class DivideAccountController extends BaseAdminController
{
/**
* @doc-name 诊所申请提现操作
* @doc-param string apply_cash 申请提现金额
* @doc-param string bank_user_name 开户人姓名
* @doc-param string bank_card 银行卡号
* @doc-param string bank_name 开户行名称
* @doc-param int bank_account_type 银行账户类型 1:对公,2:对私,5:存折
* @doc-param string bank_no 银行联行号bank_account_type=1或5或非62开头的对私银行账户时必选 / optional
* @doc-param int user_type 用户类型1诊所2总部
*/
public function actionStoreApply()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['apply_cash', 'bank_user_name', 'bank_card', 'bank_name', 'bank_account_type', 'user_type'], 'required']
]);
if ($post['apply_cash']<3){
throw new \yii\db\Exception('申请提现金额最少不能小于3元');
}
$user = \Yii::$app->user->identity;
if ($user->role != UserRoleEnum::STORE_ADMIN) {
throw new Exception('您还不是诊所管理员,没有权限申请打款');
}
if ($post['user_type'] != 1) throw new Exception('用户类型错误');
if ($post['bank_account_type'] == 1 || $post['bank_account_type'] == 5) {
if (empty($post['bank_no'])) {
throw new Exception('bank_no不能为空');
}
} else {
if (substr($post['bank_card'], 0, 2) != '62') {
if (empty($post['bank_no'])) {
throw new Exception('bank_no不能为空');
}
}
}
$t = \Yii::$app->db->beginTransaction();
try {
$order_no = 'DK' . time() . rand(111111, 999999);
$Account = CashAccount::find()->where([
'user_id' => $user->store_id,
'user_type' => 1
])->one();
if (!$Account) throw new Exception('账号不存在');
if (bcsub($Account->able_cash ,$Account->frozen_cash,2) < $post['apply_cash']) {
throw new Exception('sorry,您的账户没有那么多提现金额');
}
$CashAccount = CashAccount::find()->where([
'user_id' => $user->store_id,
'user_type' => 1
])->one();
$Platform= CashAccount::find()->where([
'user_id' => 0,
'user_type' => 2
])->one();
// $CashAccount->able_cash = bcsub($CashAccount->able_cash, $post['apply_cash'], 2);
$CashAccount->frozen_cash = bcadd($post['apply_cash'], $CashAccount->frozen_cash, 2);
$CashAccount->last_apply_time = date('Y-m-d H:i:s', time());
$CashAccount->saveOrFail();
$qianliuwu=bcdiv(0.65,100,4);
$shouxufei=bcadd(bcmul($post['apply_cash'],$qianliuwu,2),2,3);
// $Platform->updateAllCounters(['able_cash'=>1]);
// $Platform->updateAllCounters(['total_cash'=>1]);
$CashApply = new CashApply();
$CashApply->user_id = $user->store_id;//诊所id
$CashApply->user_type = 1;//用户类型1诊所2总部
$CashApply->order_no = $order_no;//申请提现金额
$CashApply->apply_cash = $post['apply_cash'];//申请提现金额
$CashApply->charge_cash =$shouxufei;//手续费
$CashApply->true_cash = bcsub($CashApply->apply_cash, $shouxufei, 2);//实际到账金额
$CashApply->apply_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
$log = new Log();
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '诊所申请打款';
$log->mold = 3;//财务操作
$log->content = '诊所管理员ID:' . $user->uid . '申请打款:' . $post['apply_cash'] . '元,订单号为:' . $order_no . ',开户人姓名为:' . $post['bank_user_name'] . ',银行卡号:' . $post['bank_card'] . ',开户行名称:' . $post['bank_name'] . ',银行账户类型:' . $post['bank_account_type'] . ',账户的冻结金额由原来的:' . $Account->frozen_cash . '元变为:' . $CashAccount->frozen_cash . '元';
$log->save();
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
$t->commit();
return ['申请成功'];
} catch (\Exception $e) {
$t->rollBack();
throw new Exception($e->getMessage());
}
}
/**
* @doc-name 平台申请提现操作
* @doc-param string apply_cash 申请提现金额
* @doc-param string bank_user_name 开户人姓名
* @doc-param string bank_card 银行卡号
* @doc-param string bank_name 开户行名称
* @doc-param int bank_account_type 银行账户类型 1:对公,2:对私,5:存折
* @doc-param string bank_no 银行联行号bank_account_type=1或5或非62开头的对私银行账户时必选 / optional
* @doc-param int user_type 用户类型1诊所2总部
*/
public function actionPlatformApply()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['apply_cash', 'bank_user_name', 'bank_card', 'bank_name', 'bank_account_type', 'user_type'], 'required']
]);
if ($post['apply_cash']<3){
throw new \yii\db\Exception('申请提现金额最少不能小于3元');
}
$user = \Yii::$app->user->identity;
if ($user->role != UserRoleEnum::SUPER_ADMIN) throw new \yii\base\Exception('您还不是超级管理员,没有权限申请打款');
if ($post['user_type'] != 2) throw new \yii\db\Exception('用户类型错误');
if ($post['bank_account_type'] == 1 || $post['bank_account_type'] == 5) {
if (empty($post['bank_no'])) {
throw new \yii\base\Exception('bank_no不能为空');
}
} else {
if (substr($post['bank_card'], 0, 2) != '62') {
if (empty($post['bank_no'])) {
throw new Exception('bank_no不能为空');
}
}
}
$t = \Yii::$app->db->beginTransaction();
try {
$order_no = 'DK' . time() . rand(111111, 999999);
$Account = CashAccount::find()->where([
'user_type' => 2,
'user_id' => 0,
])->one();
if (!$Account) throw new Exception('账号不存在');
if (bcsub($Account->able_cash,$Account->frozen_cash,2) < $post['apply_cash'])
throw new Exception('sorry,您的账户没有那么多提现金额');
$CashAccount = CashAccount::find()->where([
'user_type' => 2,//平台
'user_id' => 0,
])->one();
// $CashAccount->able_cash = bcsub($CashAccount->able_cash, $post['apply_cash'], 2);
$CashAccount->frozen_cash = bcadd($post['apply_cash'], $CashAccount->frozen_cash, 2);
$CashAccount->last_apply_time = date('Y-m-d H:i:s', time());
$CashAccount->saveOrFail();
$qianliuwu=bcdiv(0.65,100,4);
$shouxufei=bcadd(bcmul($post['apply_cash'],$qianliuwu,2),2,3);
$CashApply = new CashApply();
$CashApply->user_type = 2;
$CashApply->user_id = 0;//用户ID
$CashApply->order_no = $order_no;
$CashApply->apply_cash = $post['apply_cash'];//申请提现金额
$CashApply->charge_cash = $shouxufei;//手续费
$CashApply->true_cash = bcsub($CashApply->apply_cash, $shouxufei, 2);//实际到账金额
$CashApply->apply_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
$log = new Log();
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '平台申请打款';
$log->content = '平台ID:' . $user->uid . '申请打款:' . $post['apply_cash'] . '元,订单号为::' . $order_no . ',开户人姓名为:' . $post['bank_user_name'] . ',银行卡号:' . $post['bank_card'] . ',开户行名称:' . $post['bank_name'] . ',银行账户类型:' . $post['bank_account_type'] . ',账户冻结金额由原来的:' . $Account->frozen_cash . '元变为:' . $CashAccount->frozen_cash . '元';
$log->mold = 3;//财务操作
$log->save();
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
$t->commit();
return ['申请成功'];
} catch (\Exception $e) {
$t->rollBack();
throw new Exception($e->getMessage());
}
}
/**
* @doc-name 分账申请打款审核(超级管理员)--通过
* @doc-param int id 申请id
* @doc-param int user_type 类型1诊所2总部
* @doc-param string check_result 审核结果
*/
public function actionApplyAgree()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['id', 'check_result', 'user_type'], 'required'],
]);
$user = \Yii::$app->user->identity;
if ($user->role != UserRoleEnum::SUPER_ADMIN) throw new Exception('你不是超级管理员,没有分账申请打款审核权限');
$CashApply = CashApply::find()->where([
'id' => $post['id'],
'user_type' => $post['user_type'],
'check_status' => 1
])->one();
if (!$CashApply) throw new Exception('申请不存在');
if ($post['user_type'] == 1) {//诊所
$Account = CashAccount::find()->where([
'user_id' => $CashApply->user_id,
'user_type' => $CashApply->user_type
])->one();
$config=Store::find()->where(['id'=>$CashApply->user_id])->one();
} else {//平台
$Account = CashAccount::find()->where([
'user_id' => 0,
'user_type' => $CashApply->user_type
])->one();
$config=Admin::find()->where(['role'=>UserRoleEnum::SUPER_ADMIN])->one();
}
if (!$Account) throw new Exception('诊所或平台的账号不存在');
$CashAccount = CashAccount::find()->where([
'user_type' => $CashApply->user_type,
'user_id' => $CashApply->user_id
])->one();
if (empty($config['bank_user_name']) || empty($config['bank_card']) || empty($config['bank_name']) || empty($config['bank_account_type'])){
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);//申请提现冻结的金额
$CashAccount->saveOrFail();
$CashApply->check_id = $user->uid;
$CashApply->check_status = 4;//提现失败
$CashApply->check_result = '银行卡相关配置不完善';
$CashApply->check_time = date('Y-m-d H:i:s', time());
$CashApply->dakuan_status = -1;//失败
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
$log = new Log();
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '分账申请打款审核';
$log->content = '超级管理员:' . $user->uid . '打款操作,订单号:' . $CashApply->order_no . ',打款金额:' . bcadd($CashApply->true_cash,2,2) . '元,开户人姓名:' . $config->bank_user_name . ',银行卡号:' . $config->bank_card . ',银行名称:' . $config->bank_name . ',银行账户类型:' . $config->bank_account_type . ',打款失败,原因:银行卡相关配置不完善' ;
$log->mold = 3;//财务操作
$log->saveOrFail();
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
throw new \yii\db\Exception('银行卡相关配置不能为空');
}
$param=[
'order_no'=>$CashApply->order_no,
'apply_cash'=>bcadd($CashApply->true_cash,1,2),
'bank_name'=>$config->bank_name,
'bank_account_type'=>$config->bank_account_type,
'bank_no'=>$config->bank_no,
'bank_user_name' => $config->bank_user_name,
'bank_card' => $config->bank_card,
];
//打款
$res = EplPayService::getInstance()->withDraw($param);
//打款失败
if ($res['returnCode'] != 0000) {
try {
$transaction=\Yii::$app->db->beginTransaction();
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);//申请提现冻结的金额
$CashAccount->saveOrFail();
$CashApply->check_id = $user->uid;
$CashApply->check_status = 4;//提现失败
$CashApply->check_result = $res['returnMsg'];
$CashApply->check_time = date('Y-m-d H:i:s', time());
$CashApply->dakuan_status = -1;//失败
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
$log = new Log();
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '分账申请打款审核';
$log->content = '打款失败:超级管理员:' . $user->uid . '打款操作,订单号:' . $CashApply->order_no . ',打款金额:' . bcadd($CashApply->true_cash,2,2) . '元,开户人姓名:' . $config->bank_user_name . ',银行卡号:' . $config->bank_card . ',银行名称:' . $config->bank_name . ',银行账户类型:' . $config->bank_account_type . ',打款失败,原因:' . $res['returnMsg'];
$log->mold = 3;//财务操作
$log->saveOrFail();
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
$transaction->commit();
return $res;
}catch (\Exception $e){
$transaction->rollBack();
throw new \yii\db\Exception($e->getMessage());
}
}else{
$t = \Yii::$app->db->beginTransaction();
try {
//打款成功
$CashAccount->able_cash = bcsub($CashAccount->able_cash, $CashApply->apply_cash, 2);//账户余额
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);//申请提现冻结的金额
$CashAccount->withdrawn_cash = bcadd($CashAccount->withdrawn_cash, $CashApply->true_cash, 2);//已提现金额
$CashAccount->charge_cash = bcadd($CashAccount->charge_cash, $CashApply->charge_cash, 2);//手续费
$CashAccount->saveOrFail();
$CashApply->check_id = $user->uid;
$CashApply->check_status = 2;//成功
$CashApply->check_result = $post['check_result'];
$CashApply->check_time = date('Y-m-d H:i:s', time());
$CashApply->check_time = date('Y-m-d H:i:s', time());
$CashApply->dakuan_status = 1;//成功
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
$log = new Log();
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '分账申请打款审核';
$log->content = $user->uid . '通过了ID为:' . $post['id'] . '的打款申请,打款结果:成功';
$log->mold = 3;//财务操作
$log->save();
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
$t->commit();
return ['审核成功'];
} catch (\Exception $e) {
$t->rollBack();
throw new Exception($e->getMessage());
}
}
}
/**
* @doc-name 分账申请打款审核(超级管理员)--拒绝
* @doc-param int id 申请id
* @doc-param int user_type 类型1诊所2总部
* @doc-param string check_result 审核结果
*/
public function actionApplyRefuse()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['id', 'check_result', 'user_type'], 'required'],
]);
$user = \Yii::$app->user->identity;
if ($user->role != UserRoleEnum::SUPER_ADMIN) throw new Exception('你不是超级管理员,没有分账申请打款审核权限');
$CashApply = CashApply::find()->where([
'id' => $post['id'],
'user_type' => $post['user_type'],
'check_status' => 1,
])->one();
if (!$CashApply) throw new Exception('申请不存在');
$Account = CashAccount::find()->where([
'user_id' => $CashApply->user_id,
'user_type' => $CashApply->user_type
])->one();
if (!$Account) throw new Exception('平台或技术方的账号不存在');
$t = \Yii::$app->db->beginTransaction();
try {
$CashApply->check_id = $user->uid;
$CashApply->check_status = 3;//拒绝
$CashApply->check_result = $post['check_result'];
$CashApply->check_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
$CashAccount = CashAccount::find()->where([
'user_type' => $CashApply->user_type
])->one();
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
$CashAccount->saveOrFail();
$log = new Log();
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '分账申请打款审核';
$log->content = '管理员:' . $user->uid . '拒绝了ID为:' . $post['id'] . '的打款申请,可提现账户ID为:' . $Account->id . '的账户的冻结的金额由' . $Account->frozen_cash . '变为' . $CashAccount->frozen_cash;
$log->mold = 3;//财务操作
$log->save();
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
$t->commit();
return ['成功拒绝'];
} catch (\Exception $e) {
$t->rollBack();
throw new Exception($e->getMessage());
}
}
/**
* @doc-name 分账打款
* @doc-param int apply_id 提现申请ID
* @doc-param string order_no 订单号
* @doc-param string order_no 订单号
* @doc-param string bank_user_name 开户人姓名
* @doc-param string bank_card 银行卡号
* @doc-param string bank_name 银行名称
* @doc-param string bank_account_type 1对公2对私5存
*/
public function actionPayment()
{
$post = \Yii::$app->request->post();
$user = \Yii::$app->user->identity;
if ($user->role != UserRoleEnum::SUPER_ADMIN) throw new \yii\db\Exception('您不是超级管理员,没权限打款');
$this->requestValidate($post, [
[['apply_id', 'order_no', 'bank_user_name', 'bank_card', 'bank_name', 'bank_account_type'], 'required']
]);
$CashApply = CashApply::find()->where(['id' => $post['apply_id']])->one();
if (!$CashApply) throw new Exception('提现申请不存在');
if ($CashApply->check_status != 2) {//不是已通过状态
throw new Exception('提现申请不是已通过状态,您还不能打款');
}
$CashAccount = CashAccount::find()->where([
'user_type' => $CashApply->user_type,
'user_id' => $CashApply->user_id
])->one();
if (!$CashAccount) throw new Exception('账户不存在');
$post['apply_cash'] = $CashApply->apply_cash;
$t = \Yii::$app->db->beginTransaction();
try {
//打款
$res = EplPayService::getInstance()->withDraw($post);
//打款失败
if ($res['returnCode'] != 0000) {
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);//申请提现冻结的金额
// $CashAccount->able_cash=bcadd($CashAccount->able_cash,$CashApply->apply_cash,2);//可提现金额
$CashAccount->saveOrFail();
$CashApply->dakuan_status = -1;
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
$log = new Log();
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '超级管理员';
$log->content = '打款失败:超级管理员:' . $user->uid . '打款操作,订单号:' . $post['order_no'] . ',打款金额:' . $post['apply_cash'] . '元,开户人姓名:' . $post['bank_user_name'] . ',银行卡号:' . $post['bank_card'] . ',银行名称:' . $post['bank_name'] . ',银行账户类型:' . $post['bank_account_type'] . '打款失败:失败原因' . $res;
$log->mold = 3;//财务操作
$log->saveOrFail();
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
return $res;
}
//打款成功
$CashAccount->able_cash = bcsub($CashAccount->able_cash, $CashApply->apply_cash, 2);//账户余额
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);//申请提现冻结的金额
$CashAccount->withdrawn_cash = bcadd($CashAccount->withdrawn_cash, $CashApply->apply_cash, 2);//已提现金额
$CashAccount->charge_cash = bcadd($CashAccount->charge_cash, $CashApply->charge_cash, 2);//手续费
$CashAccount->saveOrFail();
$CashApply->dakuan_status = 1;
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
$log = new Log();
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '超级管理员';
$log->content = '打款成功:超级管理员:' . $user->uid . '打款操作:订单号:' . $post['order_no'] . ',打款金额:' . $post['apply_cash'] . '元,开户人姓名:' . $post['bank_user_name'] . ',银行卡号:' . $post['bank_card'] . ',银行名称:' . $post['bank_name'] . ',银行账户类型:' . $post['bank_account_type'];
$log->mold = 3;//财务操作
$log->saveOrFail();
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
$t->commit();
} catch (\Exception $e) {
$t->rollBack();
throw new Exception($e->getMessage());
}
}
/**
* @doc-name 分账资金流水
* @doc-param string type 1增2减 / optional
* @doc-param string content 内容 / optional
* @doc-return mixed @List{id,order_id-int-订单id,user_id-int-业务员id或仓库id其他为0,user_type-int-用户类型 1诊所 2平台,type-int-1增2减,amount-float-金额,content-string-内容,created_at-string-流水时间} 快递公司
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionDivideFundWater()
{
$get = \Yii::$app->request->get();
$user = \Yii::$app->user->identity;
$query = LedgerLog::find()->orderBy(['id' => SORT_DESC]);
if ($user->role == UserRoleEnum::STORE_ADMIN) {
$query->andWhere(['user_type' => 1]);
}
if ($user->role == UserRoleEnum::SUPER_ADMIN) {
$query->andWhere(['user_type' => [1, 2]]);
}
if (!empty($get['type'])) {
$query->andWhere(['type' => $get['type']]);
}
if (!empty($get['content'])) {
$query->andWhere(['like', 'content', $get['content']]);
}
$this->field = [
LedgerLog::class => [
'id', 'order_id', 'user_id', 'username' => function ($m) {
return Admin::find()->select(['username'])->where(['uid' => $m->user_id])->column();
}, 'user_type', 'type', 'amount', 'content',
'created_at' => function ($m) {
return date('Y-m-d H:i:s', $m->created_at);
}
]
];
return $this->create($query, $get);
}
/**
* @doc-name 首页数据
* @doc-return mixed @List{id,user_id-int-用户ID,total_cash-float-累计收益,able_cash-int-账户余额,frozen_cash-int-申请提现冻结的金额,withdrawn_cash-int-已提现金额,wait_cash-float-待结算收益,charge_cash-float-手续费,user_type-int-用户类型 1诊所 2平台,last_apply_time-string-最近提现申请时间,account-string-账户} 首页数据
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionHomeData()
{
$get = \Yii::$app->request->get();
$QUERY = CashAccount::find();
$this->field = [
CashAccount::class => [
'id', 'user_id', 'total_cash', 'able_cash', 'frozen_cash', 'withdrawn_cash', 'wait_cash', 'charge_cash',
'account' => function ($m) {
if ($m->user_id == 0) {
return Admin::find()->where(['role' => UserRoleEnum::SUPER_ADMIN])->one();
} else {
return Store::find()->where(['id' => $m->user_id])->one();
}
},
'user_type',
'last_apply_time'
]
];
return $this->create($QUERY, $get);
}
/**
* @doc-name 平台的提现账户
* @doc-return string user_id 用户
* @doc-return string total_cash 累计收益
* @doc-return string able_cash 账户余额
* @doc-return string frozen_cash 申请提现冻结的金额
* @doc-return string withdrawn_cash 待结算收益
* @doc-return string wait_cash 已提现金额
* @doc-return string charge_cash 手续费
* @doc-return string user_type 用户类型 1诊所 2平台
* @doc-return string last_apply_time 最近提现申请时间
*/
public function actionPlatformAccount()
{
$get = \Yii::$app->request->get();
$user = \Yii::$app->user->identity;
$CashAccount = CashAccount::find()->where(['user_id' => 0, 'user_type' => 2])->one();
if (!$CashAccount) throw new \yii\db\Exception('账户不存在');
$price=Ledger::find()->where(['status'=>0,'user_type'=>2,'user_id'=>0])->sum('money');
$CashAccount->total_cash=bcadd(bcadd($CashAccount->able_cash,$CashAccount->withdrawn_cash,2),$CashAccount->charge_cash,2);
$CashAccount->wait_cash=$price;
$CashAccount->saveOrFail();
return $CashAccount;
}
/**
* @doc-name 诊所提现账户
* @doc-param int store_id 诊所ID
* @doc-return string user_id 用户
* @doc-return string total_cash 累计收益
* @doc-return string able_cash 账户余额
* @doc-return string frozen_cash 申请提现冻结的金额
* @doc-return string withdrawn_cash 待结算收益
* @doc-return string wait_cash 已提现金额
* @doc-return string charge_cash 手续费
* @doc-return string user_type 用户类型 1诊所2平台
* @doc-return string last_apply_time 最近提现申请时间
*/
public function actionStoreAccount()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get, [
['store_id', 'required'],
]);
$store = Store::find()->where(['id' => $get['store_id']])->one();
if (!$store) throw new \yii\db\Exception('诊所不存在');
$CashAccount = CashAccount::find()->where(['user_id' => $get['store_id'], 'user_type' => 1])->one();
if (!$CashAccount) throw new \yii\db\Exception('账户不存在');
$price=Ledger::find()->where(['status'=>0,'user_type'=>1,'user_id'=>$CashAccount->user_id])->sum('money');
$CashAccount->total_cash=bcadd(bcadd($CashAccount->able_cash,$CashAccount->withdrawn_cash,2),$CashAccount->charge_cash,2);
$CashAccount->wait_cash=$price??0;
$CashAccount->saveOrFail();
return $CashAccount;
}
/**
* @doc-name 分账--审核管理列表
* @doc-param int status 1待审核2审核通过3审核拒绝
* @doc-return mixed @List{id,user_id-int-用户ID,user_type-int-用户类型1诊所2总部,order_no-int-订单,apply_cash-float-申请提现金额,true_cash-float-实际到账金额,charge_cash-string-手续费,check_id-string-关联admin表 审核人ID,check_status-string-审核状态0待审核1审核中2已通过3已拒绝,check_result-string-审核结果/拒绝原因,check_time-string-审核时间,apply_time-string-申请时间,dakuan_status-string-打款状态-1失败0未知1成功,dakuan_time-string-打款时间,payee-string-收款人} 审核管理列表
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionCheckManage()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get, [
['status', 'required']
]);
$query = CashApply::find()->orderBy(['id' => SORT_DESC]);
switch ($get['status']) {
case 1:
$query->andWhere(['check_status' => [0, 1]]);
break;
case 2:
$query->andWhere(['check_status' => 2]);
break;
case 3:
$query->andWhere(['check_status' => 3]);
break;
default:
throw new \yii\db\Exception('参数错误');
}
if(!empty($get['start_time']) && !empty($get['end_time'])){
$start_time=strtotime($get['start_time'].' '.'00:00:00');
$end_time=strtotime($get['end_time'].' '.'23:59:59');
$query->andWhere(['between','created_at',$start_time,$end_time]);
}
if(!empty($get['name'])){
if($get['name'] == '平台'){
$query->andWhere(['user_id' => 0]);
}else{
$store = Store::find()->where(['name'=>$get['name']])->asArray()->one();
if($store){
$query->andWhere(['user_id' => intval($store['id'])]);
}else{
$query->andWhere(['user_id' => -1]);
}
}
}
$this->field = [
CashApply::class => [
'id', 'user_id', 'user_type', 'order_no', 'apply_cash', 'true_cash', 'charge_cash', 'check_id', 'check_status', 'check_result', 'check_time', 'apply_time', 'dakuan_status', 'dakuan_time', 'payee' => function ($m) {
if ($m->user_id == 0) {
return Admin::find()->where(['role' => UserRoleEnum::SUPER_ADMIN])->one();
} else {
return Store::find()->where(['id' => $m->user_id])->one();
}
}
]
];
return $this->create($query, $get);
}
/**
* @doc-name 导出提现审核
*/
public function actionExportWithDraw()
{
\Yii::$app->response->format = Response::FORMAT_RAW;
$params = \Yii::$app->request->get();
$parameter['header'] = ['订单号', '平台/诊所', '收款人', '申请提现金额', '审核状态', '时间'];
$parameter['data'] = CashApply::inventory($params,\Yii::$app->user->identity->store_id);
ExportService::ExportByCors($parameter);
}
/**
* @doc-name 分账--财务数据
* @doc-param float total_cash 累计收益
* @doc-param float able_cash 账户余额
* @doc-param float withdrawn_cash 已体现
* @doc-param float charge_cash 手续费
* @doc-param float wait_cash 待结算
*/
public function actionFenzhangFinance()
{
//总收入
$total_price=CashAccount::find()->sum('total_cash');
//账户余额
$account_price=CashAccount::find()->sum('able_cash');
$withdrawn_cash=CashAccount::find()->sum('withdrawn_cash');
$charge_cash=CashAccount::find()->sum('charge_cash');
// $wait_cash=CashAccount::find()->sum('wait_cash');
$wait_cash=Ledger::find()->where(['status'=>0])->sum('money');
return [
'total_cash'=>$total_price,
'able_cash'=>$account_price,
'withdrawn_cash'=>$withdrawn_cash,
'charge_cash'=>$charge_cash,
'wait_cash'=>$wait_cash??0,
];
}
/**
* @doc-name 分账--财务数据的明细
*/
public function actionFenzhangFinanceDetail()
{
$CashApply=CashApply::find()->orderBy(['id'=>SORT_DESC])->all();
$Ledger=Ledger::find()->orderBy(['id'=>SORT_DESC])->with(['productOrder'])->asArray()->all();
return [
'CashApply'=>$CashApply,
'Ledger'=>$Ledger,
];
}
/**
* @doc-name 平台/诊所提现管理
* @doc-return mixed @List{id,user_id-int-用户ID,user_type-int-用户类型1诊所2总部,order_no-int-订单,apply_cash-float-申请提现金额,true_cash-float-实际到账金额,charge_cash-string-手续费,check_id-string-关联admin表 审核人ID,check_status-string-审核状态0待审核1审核中2已通过3已拒绝,check_result-string-审核结果/拒绝原因,check_time-string-审核时间,apply_time-string-申请时间,dakuan_status-string-打款状态-1失败0未知1成功,dakuan_time-string-打款时间,payee-string-收款人} 平台/诊所提现管理
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionWithdrawnManage()
{
$get = \Yii::$app->request->get();
$user = \Yii::$app->user->identity;
$order_no=$get['order_no'];
$query = CashApply::find()->alias('c')->orderBy(['id' => SORT_DESC]);
if (!empty($order_no)){
$query->andWhere(['c.order_no'=>$order_no]);
}
if (!empty($get['start_time']) && !empty($get['end_time'])){
$query->andWhere(['between','c.apply_time',$get['start_time'],$get['end_time']]);
}
if ($user->role==UserRoleEnum::SUPER_ADMIN){//平台
$query->andWhere(['c.user_id'=>0,'c.user_type'=>2]);
}else{
$query->andWhere(['c.user_id'=>$user->store_id,'c.user_type'=>1]);
}
$this->field = [
CashApply::class => [
'id', 'user_id', 'user_type', 'order_no', 'apply_cash', 'true_cash', 'charge_cash', 'check_id', 'check_status', 'check_result', 'check_time', 'apply_time', 'dakuan_status', 'dakuan_time', 'payee' => function ($m) {
if ($m->user_id == 0) {
return Admin::find()->where(['role' => UserRoleEnum::SUPER_ADMIN])->one();
} else {
return Store::find()->where(['id' => $m->user_id])->one();
}
},
'type' => function ($c) {//结算类别
return '提现记录';
},
'status' => function ($ca) {
if ($ca->check_status == 1 ) {
return '审核中';
} elseif($ca->check_status == 2) {
return '审核通过,提现成功';
}elseif($ca->check_status == 3) {
return '申请已拒绝,手续费未扣';
}elseif($ca->check_status == 4 ) {
return '审核通过,提现失败';
}else{
return '未知';
}
},
'tixian_person'=>function($m){
if ($m->user_type==1)return '诊所';
if ($m->user_type==2)return '平台';
},
],
];
return $this->create($query, $get);
}
/**
* @doc-name 平台/诊所结算列表
* @doc-param string order_no 产品订单号
* @doc-param string register_no 挂号订单号
* @doc-param string start_time 开始时间
* @doc-param string end_time 结束时间
* @doc-return mixed @List{id,user_id-int-用户ID,user_type-int-用户类型1诊所2总部,order_no-int-订单,order_id-int-订单id,su_id-int-医生id,drugstore_id-int-仓库id,drug_id-string-药品id,status-string-结算状态 0待结算 1已结算 2已取消,money-string-分佣金额,time-string-时间} 平台/诊所是否结算管理
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionJiesuanList()
{
$get = \Yii::$app->request->get();
$user = \Yii::$app->user->identity;
$order_no=$get['order_no'];
$register_no=$get['register_no'];
$start_time=strtotime($get['start_time']);
$end_time=strtotime($get['end_time']);
$query = Ledger::find()->alias('l')->where(['l.status'=>[0,1]])->orderBy(['l.id' => SORT_DESC]);
if (!empty($order_no)){
$query->joinWith(['productOrder'=>function($p)use($order_no){
$p->where(['order_no'=>$order_no]);
}]);
}
if (!empty($register_no)){
$query->joinWith(['register'=>function($p)use($register_no){
$p->where(['order_no'=>$register_no]);
}]);
}
if (!empty($start_time) && !empty($end_time)){
if ($start_time==$end_time){//筛选某一天
$time=FuncHelper::getDayBE($get['start_time']);
$end_time=$time[1];
}
$query->andWhere(['between','l.created_at',$start_time,$end_time]);
}
if ($user->role==UserRoleEnum::SUPER_ADMIN){//平台
$query->andWhere(['l.user_id'=>0,'l.user_type'=>2])->groupBy('l.order_id,l.order_type');
}else{
$query->andWhere(['l.user_id'=>$user->store_id,'l.user_type'=>1])->groupBy('l.order_id,l.order_type');
}
$this->field = [
Ledger::class => [
'id', 'user_id','order_id', 'user_type','su_id', 'drugstore_id', 'drug_id', 'status', 'money'=> function ($m) {
return $this->actionTotal($m->order_id,$m->user_type,$m->order_type);
},
'order_no'=> function ($order) {
if ($order->order_type == 1) {
return ProductOrder::find()->select(['order_no'])->where(['id' => $order->order_id])->column();
}
if ($order->order_type == 2) {
return Register::find()->select(['order_no'])->where(['id' => $order->order_id])->column();
}
},
'type'=>function($l){
if ($l->order_type==1){
return '产品订单';
}else{
return '挂号订单';
}
},
'fee_type'=>function($f){
if ($f->fee_type==1){
return '药品费用';
}elseif($f->fee_type==2){
return '挂号费用';
}elseif($f->fee_type==3){
return '快递费用';
}elseif($f->fee_type==4){
return '代煎费用';
}else{
return '其他';
}
},
'price_from'=>'productOrder.user.nickname',
'time'=>function($le){
return date('Y-m-d H:i:s',$le->created_at);
}
],
];
return $this->create($query, $get);
}
public function actionTotal($order_id='',$user_type=1,$order_type='')
{
$money = Ledger::find()->alias('l')->where(['l.order_id' => $order_id, 'l.status' => [0, 1]])->andWhere(['l.user_type'=>$user_type,'l.order_type'=>$order_type])->sum('money');
return $money ?? 0;
}
}

View File

@@ -0,0 +1,439 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use admin\models\Admin;
use common\enums\UserRoleEnum;
use common\forms\ProductRefundForm;
use common\helpers\FuncHelper;
use common\models\CashApply;
use common\models\FundWater;
use common\models\Ledger;
use common\models\ProductOrder;
use common\models\ProductOrderRefund;
use common\models\Register;
use common\models\Store;
use common\models\SystemNotice;
use common\services\ExportService;
use yii\db\Exception;
use yii\web\Response;
class FinanceController extends BaseAdminController
{
/**
* @doc-name 退款申请记录
* @doc-param string refund_no 退款单号 / optional
* @doc-return @List{id,order_id-int-订单id,user_id-int-用户ID,reason-string-原因,remark-string-备注,refund_images-string-退款图片,refund_type-int-0仅退款 1退货退款,refund_no-string-退款单号,fail_reason-string-失败原因,refund_price-float-金额,is_refund-int-0待退款 1已退款 -1退款失败,refund_time-string-退款时间,status-int-0退款申请中 1申请通过 2撤销申请3拒绝退款} 退款申请记录
*/
public function actionRefundApply()
{
$get = \Yii::$app->request->get();
$user = \Yii::$app->user->identity;
if ($user->role == UserRoleEnum::STORE_ADMIN) {
$query = ProductOrderRefund::find()->alias('po')->where([
'po.is_deleted' => 0
])->orderBy(['po.id' => SORT_DESC]);
// $query->joinWith(['order' => function ($model) use ($user) {
// $model->andWhere(['drugstore_id' => $user->drugstore]);
// }]);
}
if ($user->role == UserRoleEnum::SUPER_ADMIN) {
$query = ProductOrderRefund::find()->alias('po')->where([
'is_deleted' => 0
])->orderBy(['po.id' => SORT_DESC]);
}
if (!empty($get['refund_no'])) {
$query->andWhere(['refund_no' => $get['refund_no']]);
}
$this->field = [
ProductOrderRefund::class => [
'id', 'order_id', 'user_id', 'reason', 'remark', 'refund_images', 'refund_type', 'refund_no', 'refund_price', 'is_refund', 'refund_time',
'status', 'created_at' => function ($m) {
return date('Y-m-d H:i:s', $m->created_at);
}
]
];
return $this->create($query, $get);
}
/**
* @doc-name 同意退款操作
* @doc-param int id 退款申请记录ID
*/
public function actionRefundAgree()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
['id', 'required'],
]);
$user = \Yii::$app->user->identity;
$t = \Yii::$app->db->beginTransaction();
try {
$ProductOrderRefund = ProductOrderRefund::find()->where([
'id' => $post['id'],
'is_deleted' => 0,
])->with(['order'])->one();
if (!$ProductOrderRefund) {
throw new Exception('退款申请记录不存在');
}
$ProductOrder = ProductOrder::find()->where(['id' => $ProductOrderRefund->order_id])->one();
if (!$ProductOrder) throw new Exception('产品订单不存在');
$ProductOrder->refund_status = 3;//已退款
$ProductOrder->saveOrFail();
$ProductOrderRefund->is_refund = 1;
$ProductOrderRefund->status = 1;
$ProductOrderRefund->refund_time = date('Y-m-d H:i:s', time());
$ProductOrderRefund->saveOrFail();
$form = new ProductRefundForm();
$form->refundMoney($ProductOrderRefund);
$t->commit();
return ['success'];
} catch (\Exception $e) {
$t->rollBack();
throw new Exception($e->getMessage());
}
}
/**
* @doc-name 拒绝退款操作
* @doc-param int id 退款申请记录ID
* @doc-param string check_result 拒绝原因
*/
public function actionRefundRefuse()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['id_id', 'check_result'], 'required'],
]);
$id = $post['id_id'];
$user = \Yii::$app->user->identity;
if ($user->role == UserRoleEnum::SUPER_ADMIN) {//超管
$ProductOrderRefund = ProductOrderRefund::find()->where([
'id' => $id,
'is_deleted' => 0,
])->with(['order'])->one();
}
if ($user->role == UserRoleEnum::STORE_ADMIN) {//门店管理员
$ProductOrderRefund = ProductOrderRefund::find()->alias('po')->where([
'po.id' => $id,
'po.is_deleted' => 0,
])->with(['order'])->one();
}
if (!$ProductOrderRefund) throw new Exception('退款申请记录不存在');
$t = \Yii::$app->db->beginTransaction();
try {
$ProductOrder = ProductOrder::find()->where(['id' => $ProductOrderRefund->order_id])->one();
if (!$ProductOrder) throw new Exception('产品订单不存在');
if ($ProductOrder->is_send == 1) {
$ProductOrder->status = 6;//确认收货
} else {
$ProductOrder->status = 1;//待发货
}
$ProductOrder->refund_status = 4;//拒绝退款
$ProductOrder->saveOrFail();
$ProductOrderRefund->is_refund = 0;
$ProductOrderRefund->status = 3;//拒绝退款
$ProductOrderRefund->check_result = $post['check_result'];//审核结果
$ProductOrderRefund->refund_time = date('Y-m-d H:i:s', time());
$ProductOrderRefund->saveOrFail();
//拒绝退款通知
$systemNotice = new SystemNotice();
$systemNotice->store_id = $ProductOrder->store_id;
$systemNotice->content = '工作人员已拒绝退款,原因:' . $post['check_result'];
$systemNotice->base_type = 7;
$systemNotice->scene_type = 1;
$systemNotice->user_id = $ProductOrderRefund->user_id;
$systemNotice->notice_at = date('Y-m-d h:i:s', time());
$systemNotice->saveOrFail();
$t->commit();
return ['success'];
} catch (\Exception $e) {
$t->rollBack();
throw new Exception($e->getMessage());
}
}
/**
* @doc-name 资金流水记录
* @doc-param string start_time 时间 / optional
* @doc-param string end_time 时间 / optional
* @doc-param string doctor 医生 / optional
* @doc-param string store 诊所 / optional
* @doc-param string order_no 订单号 / optional
* @doc-param string refund_no 退款单号 / optional
* @doc-return @List{id,order_id-int-订单id,order_type-int-订单类型1产品订单2问诊订单,user_id-int-用户ID,type-string-类型enter入账refund出账,price-float-金额,order_no-string-订单号,refund_no-string-退款单号,created_at-string-收入或支出时间,pay_type-int-支付类型1为微信} 资金流水记录
*/
public function actionFundWater()
{
$get = \Yii::$app->request->get();
$user = \Yii::$app->user->identity;
$start_time=strtotime($get['start_time']);
$end_time=strtotime($get['end_time']);
$doctor = $get['doctor'];
$store = $get['store'];
if ($user->role == UserRoleEnum::STORE_ADMIN) {
$query = FundWater::find()->where([
'f.store_id' => $user->store_id
])->alias('f')->orderBy(['id' => SORT_DESC]);
}
if ($user->role == UserRoleEnum::SUPER_ADMIN) {
$query = FundWater::find()->alias('f')->orderBy(['id' => SORT_DESC]);
}
if (!empty($start_time) && !empty($end_time)) {
if ($start_time==$end_time){//筛选当天
$time=FuncHelper::getDayBE($get['start_time']);
$end_time=$time[1];
}
$query->andWhere(['between', 'f.created_at', $start_time,$end_time]);
}
if (!empty($doctor)) {
$query->joinWith(['doctor' => function ($d) use ($doctor) {
$d->alias('d');
$d->andWhere(['like', 'd.name', $doctor]);
}]);
}
if (!empty($store)) {
$query->joinWith(['store' => function ($s) use ($store) {
$s->alias('s');
$s->andWhere(['like', 's.name', $store]);
}]);
}
if (!empty($get['order_no'])) {
$query->andWhere(['f.order_no' => $get['order_no']]);
}
if (!empty($get['refund_no'])) {
$query->andWhere(['f.refund_no' => $get['refund_no']]);
}
$this->field = [
FundWater::class => [
'id', 'order_id', 'order_type', 'user_id', 'type', 'price', 'order_no', 'refund_no', 'pay_type', 'store_id',
'created_at' => function ($m) {
return date('Y-m-d H:i:s', $m->created_at);
},
'store' => 'store.name', 'service_user_id', 'doctor' => 'doctor.name',
'user' => 'user.nickname'
]
];
return $this->create($query, $get);
}
/**
* @doc-name 导出资金流水
*/
public function actionExportFundWater()
{
\Yii::$app->response->format = Response::FORMAT_RAW;
$params = \Yii::$app->request->post();
$parameter['header'] = ['订单类型', '医生', '用户', '价格', '诊所', '时间'];
$parameter['data'] = FundWater::inventory($params,\Yii::$app->user->identity->store_id);
ExportService::ExportByCors($parameter);
}
/**
* @doc-name 财务数据--结算记录(包括平台和门诊的)
* @doc-param string order_no 产品订单号
* @doc-param string register_no 挂号订单号
* @doc-param string start_time 开始时间
* @doc-param string end_time 结束时间
* @doc-param string order_no 订单
* @doc-return mixed @List{id,user_id-int-用户ID,user_type-int-用户类型1诊所2总部,order_no-int-订单,order_id-int-订单id,su_id-int-医生id,drugstore_id-int-仓库id,drug_id-string-药品id,status-string-结算状态 0待结算 1已结算 2已取消,money-string-分佣金额,time-string-时间} 平台/诊所是否结算管理
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionJiesuanList()
{
$get = \Yii::$app->request->get();
$order_no = $get['order_no'];
$register_no = $get['register_no'];
$start_time=strtotime($get['start_time'].' '.'00:00:00');
$end_time=strtotime($get['end_time'].' '.'23:59:59');
$query = Ledger::find()->alias('l')->where(['l.status' => [0, 1]])->orderBy(['id' => SORT_DESC])->groupBy('l.order_id,l.order_type');
if (!empty($order_no)) {
$query->joinWith(['productOrder' => function ($p) use ($order_no) {
$p->where(['order_no' => $order_no]);
}]);
}
if (!empty($register_no)){
$query->joinWith(['register'=>function($p)use($register_no){
$p->where(['order_no'=>$register_no]);
}]);
}
if (!empty($start_time) && !empty($end_time)) {
if ($start_time==$end_time){//筛选当天
$time=FuncHelper::getDayBE($get['start_time']);
$end_time=$time[1];
}
$query->andWhere(['between', 'l.created_at', $start_time, $end_time]);
}
$this->field = [
Ledger::class => [
'id', 'user_id', 'user_type', 'su_id', 'drugstore_id', 'drug_id', 'status', 'money' => function ($m) {
return $this->actionTotal($m->order_id);
},
'order_id',
'order_no' => function ($order) {
if ($order->order_type == 1) {
return ProductOrder::find()->select(['order_no'])->where(['id' => $order->order_id])->column();
}
if ($order->order_type == 2) {
return Register::find()->select(['order_no'])->where(['id' => $order->order_id])->column();
}
},
'type' => function ($l) {
if ($l->order_type == 1) {
return '产品订单';
} else {
return '挂号订单';
}
},
'fee_type' => function ($f) {
if ($f->fee_type == 1) {
return '药品费用';
} elseif ($f->fee_type == 2) {
return '挂号费用';
} elseif ($f->fee_type == 3) {
return '快递费用';
} elseif ($f->fee_type == 4) {
return '代煎费用';
} else {
return '其他';
}
},
'price_from' => 'productOrder.user.nickname',
'time' => function ($le) {
return date('Y-m-d H:i:s', $le->created_at);
}
],
];
return $this->create($query, $get);
}
public function actionTotal($order_id)
{
$money = Ledger::find()->alias('l')->where(['l.order_id' => $order_id, 'l.status' => [0, 1]])->sum('money');
return $money ?? 0;
}
/**
* @doc-name 财务数据--提现记录
* @doc-param string order_no 订单号
* @doc-param string start_time 开始时间
* @doc-param string end_time 结束时间
* @doc-return mixed @List{id,user_id-int-用户ID,user_type-int-用户类型1诊所2总部,order_no-int-订单,apply_cash-float-申请提现金额,true_cash-float-实际到账金额,charge_cash-string-手续费,check_id-string-关联admin表 审核人ID,check_status-string-审核状态0待审核1审核中2已通过3已拒绝,check_result-string-审核结果/拒绝原因,check_time-string-审核时间,apply_time-string-申请时间,dakuan_status-string-打款状态-1失败0未知1成功,dakuan_time-string-打款时间,payee-string-收款人} 平台/诊所提现管理
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionWithdrawnManage()
{
$get = \Yii::$app->request->get();
$order_no = $get['order_no'];
$start_time=strtotime($get['start_time'].' '.'00:00:00');
$end_time=strtotime($get['end_time'].' '.'23:59:59');
$query = CashApply::find()->alias('c')->orderBy(['id' => SORT_DESC]);
if (!empty($order_no)) {
$query->where(['c.order_no' => $order_no]);
}
if (!empty($start_time) && !empty($end_time)) {
if ($start_time==$end_time){//筛选当天
$time=FuncHelper::getDayBE($get['start_time']);
$start_time=$get['start_time'];
$end_time=date('Y-m-d H:i:s',$time);
}else{
$start_time=$get['start_time'];
$end_time=$get['end_time'];
}
$query->andWhere(['between', 'c.apply_time',$start_time,$end_time]);
}
$this->field = [
CashApply::class => [
'id', 'user_id', 'user_type', 'order_no', 'apply_cash', 'true_cash', 'charge_cash', 'check_id', 'check_status', 'check_result', 'check_time', 'apply_time', 'dakuan_status', 'dakuan_time', 'payee' => function ($m) {
if ($m->user_id == 0) {
return Admin::find()->where(['role' => UserRoleEnum::SUPER_ADMIN])->one();
} else {
return Store::find()->where(['id' => $m->user_id])->one();
}
},
'type' => function ($c) {//结算类别
return '提现记录';
},
'status' => function ($ca) {
if ($ca->check_status == 1) {
return '审核中';
} elseif ($ca->check_status == 2) {
return '审核通过,提现成功';
} elseif ($ca->check_status == 3) {
return '申请已拒绝,手续费未扣';
} elseif ($ca->check_status == 4) {
return '审核通过,提现失败';
} else {
return '未知';
}
},
'tixian_person' => function ($m) {
if ($m->user_type == 1) return '诊所';
if ($m->user_type == 2) return '平台';
},
],
];
return $this->create($query, $get);
}
/**
* @doc-name 导出提现、结算记录
*/
public function actionExportSettlement()
{
\Yii::$app->response->format = Response::FORMAT_RAW;
$params = \Yii::$app->request->get();
if($params['type'] == 1){
$parameter['header'] = ['单号','提现方', '提现金额', '到账金额','手续费', '状态', '时间'];
$parameter['data'] = CashApply::inventory1($params);
}else{
$parameter['header'] = ['单号','订单类型', '用户', '金额', '状态', '时间'];
$parameter['data'] = Ledger::inventory($params,\Yii::$app->user->identity->store_id);
}
ExportService::ExportByCors($parameter);
}
}

View File

@@ -0,0 +1,174 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use admin\models\forms\drug\NavForm;
use common\enums\UserRoleEnum;
use common\models\Nav;
use yii\db\Exception;
class NavController extends BaseAdminController
{
/**
* @doc-name 轮播图类型
*/
public function actionTypeList()
{
return [
['key' => 0, 'value' => '轮播图'],
];
}
/**
* @doc-name 轮播图列表
* @doc-param int is_home 是否首页0否1是 / optional
* @doc-param int type 类型1活动2专题 / optional
* @doc-return mixed @nav{id,pic,external_link-string-外部链接,is_home-int-是否首页0否1是,home_time-string-首页时间,type-int-类型1活动2专题} 轮播图
*/
public function actionList()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get, [
['store_id', 'required']
]);
$admin = \Yii::$app->user->identity;
$query = Nav::find()->where([
'store_id' => $get['store_id'],
'is_delete' => 0,
])->orderBy(['id' => SORT_DESC]);
if (!empty($get['is_home'])) {
$query->andWhere([
'is_home' => $get['is_home']
]);
}
if (!empty($get['type'])) {
$query->andWhere([
'type' => $get['type']
]);
}
$this->field = [
Nav::class => [
'id', 'pic', 'external_link', 'is_home', 'home_time', 'type', 'sort', 'store_id','link_type'
]
];
return $this->create($query, $get);
}
/**
* @doc-name 新增轮播图
* @doc-param int store_id 门店ID / optional
* @doc-param int sort 排序 / optional
* @doc-param string pic 轮播图
* @doc-param int link_type 1内部2外部 / optional
* @doc-param string external_link 外部链接 / optional
* @doc-param int is_home 是否首页0否1是 / optional
* @doc-param int type 类型1轮播图 / optional
*/
public function actionSaveNav()
{
$post = \Yii::$app->request->post();
$NavForm = new NavForm();
$NavForm->attributes = $post;
return $NavForm->save();
}
/**
* @doc-name 修改轮播图
* @doc-param int id 轮播图id
* @doc-param string store_id 门店ID
* @doc-param string sort 排序
* @doc-param string pic 轮播图
* @doc-param string external_link
* @doc-param int is_home 是否首页0否1是
* @doc-param int type 类型1活动2专题
*/
public function actionEditNav()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
['id', 'required']
]);
$NavForm = new NavForm();
$NavForm->attributes = $post;
return $NavForm->update();
}
/**
* @doc-name 删除轮播图
* @doc-param int id 轮播图id
*/
public function actionDel()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get, [
['id', 'required']
]);
$NavForm = new NavForm();
$NavForm->attributes = $get;
return $NavForm->del();
}
/**
* @doc-name 轮播图详情
* @doc-param int id 轮播图id
* @doc-return mixed @nav{*} 轮播图
*/
public function actionInfo()
{
$get =\Yii::$app->request->get();
$this->requestValidate($get, [
['id', 'required']
]);
$nav = Nav::find()->where([
'id' => $get['id'],
'is_delete' => 0
])->one();
if (!$nav) throw new Exception('轮播图不存在');
return $nav;
}
/**
* @doc-name 是否推送的首页
* @doc-param int id 轮播图id
* @doc-param int status 状态0否1是
*/
public function actionIsHome()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['id', 'status'], 'required']
]);
$nav = Nav::find()->where([
'id' => $post['id'],
'is_delete' => 0
])->one();
if (!$nav) throw new Exception('轮播图不存在');
switch ($post['status']) {
case 0:
$nav->is_home = 0;
$nav->home_time = date('Y-m-d H:i:s', time());
$nav->saveOrFail();
return ['已取消'];
break;
case 1:
$nav->is_home = 1;
$nav->home_time = date('Y-m-d H:i:s', time());
$nav->saveOrFail();
return ['已推送'];
break;
default:
throw new Exception('参数错误');
}
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use common\models\SystemNotice;
/**
* @doc-module 公告
*/
class NoticeController extends BaseAdminController
{
/**
* @doc-name 公告列表
*/
public function actionList()
{
$get = \Yii::$app->request->get();
$query = SystemNotice::find()->where(['base_type'=>99]);
$this->field = [
SystemNotice::class => [
'id', 'scene_type', 'content','base_type'
]
];
return $this->create($query,$get);
}
/**
* @doc-name 发送公告
* @doc-param string content 发送公告
* @doc-param int type 3全部4所有医生5所有用户 发送公告
*/
public function actionAddNotice()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get, [
[['type', 'content'], 'required']
]);
$SystemNotice = new SystemNotice();
$SystemNotice->content = $get['content'];
$SystemNotice->scene_type = $get['type'];
$SystemNotice->base_type = 99;
$SystemNotice->saveOrFail();
}
}

View File

@@ -0,0 +1,511 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use common\enums\UserRoleEnum;
use common\events\ProductOrderEvent;
use common\forms\ProductCancelForm;
use common\forms\ProductRefundForm;
use common\helpers\FuncHelper;
use common\jobs\ProductOrderSendJob;
use common\models\DrugStore;
use common\models\Prescription;
use common\models\ProductOrder;
use common\models\ProductOrderItems;
use common\models\ProductOrderRefund;
use common\models\Store;
use common\models\SystemConfig;
use common\models\UserPatient;
use common\services\ExportService;
use common\services\ExpressService;
use yii\db\Exception;
use yii\helpers\Json;
use yii\web\Response;
class OrderController extends BaseAdminController
{
/**
* @doc-name 产品订单列表
* @doc-param string order_no 订单编号 / optional
* @doc-param string good_name 商品名称 / optional
* @doc-param string accept_name 收件人姓名 / optional
* @doc-param string accept_tel 收件人电话 / optional
* @doc-param string doctor 医生搜索 / optional
* @doc-param string store 门店 / optional
* @doc-param int status 产品订单状态0未支付1待发货2待收货3待评价4已退款5退款中6已收货7确认收货9已取消 / optional
* @doc-param int after_status 售后状态1申请退款2同意退款3已退款9取消退款 / optional
* @doc-param string start_time 开始时间 / optional
* @doc-param string end_time 结束时间 / optional
* @doc-return mixed @List{id,store_id-int-门店ID,p_id,user_id-int-用户id,up_id-int-就诊人id,status-int-产品订单状态0未支付1待发货2待收货3待评价4已退款5退款中6已收货7确认收货,cancel_status-int-取消状态1已取消,cancel_time-string-取消时间,cancel_remark-string-取消备注(未支付超时取消,主动取消,拒绝取消),refund_status-int-退款状态1退款中2已退款,refund_type-int-退款类型0仅退款1退货退款,refund_time-string-退款时间,drugstore-string-发货仓库,total_pay_price-float-总价,pay_time-string-支付时间,order_no-string-订单编号,is_has-int-是否有处方,doctor-string-开方医生,good-int-商品信息,trans_expenses-float-运费(默认包邮),free_ship-int-是否包邮,remark-string-留言备注,express_name-string-收货人,express_mobile-string-收货电话,express_region-string-收货省市区,@Prescription{id-int-id,platform_prescription_no-string-平台处方单号,prescription_no-string-处方单号,order_id-int-订单id,status-int-状态 0待审核,1已通过,2未通过,content-string-处方快照,prescription_type-int-1中药处方2西药处方3颗粒药处方,category-int-类别1自费2医保,doctor_order-string-医嘱,clinical_diagnose-string-临床诊断,医生签名-string-医生签名,type-int-类型1普通方2常用方,order_type-int-订单类型1处方2医技,total_pay_price-float-支付金额},decoct_price-float-代煎费用,is_decoct-int-1需要代煎} 商品订单列表
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionProductList()
{
$get = \Yii::$app->request->get();
$good_name = $get['good_name'];
$store = $get['store'];
$doctor = $get['doctor'];
$type=$get['type'];
$admin = \Yii::$app->user->identity;
$start_time=strtotime($get['start_time'].' '.'00:00:00');
$end_time=strtotime($get['end_time'].' '.'23:59:59');
if ($admin->role == UserRoleEnum::STORE_ADMIN) {//门店
$query = ProductOrder::find()->alias('pd')->where(['pd.store_id' => $admin->store_id])->orderBy(['pd.id' => SORT_DESC]);
} elseif ($admin->role == UserRoleEnum::PROVINCE_DAI){//省代
$store_id = Store::find()->select(['id'])->where(['province_id' => $admin->province_id])->column();
$query = ProductOrder::find()->alias('pd')->where(['in','pd.store_id',$store_id])->orderBy(['pd.id' => SORT_DESC]);
} elseif ($admin->role == UserRoleEnum::CITY_DAI){//市代
$store_id = Store::find()->select(['id'])->where(['city_id' => $admin->city_id])->column();
$query = ProductOrder::find()->alias('pd')->where(['in','pd.store_id',$store_id])->orderBy(['pd.id' => SORT_DESC]);
} elseif ($admin->role == UserRoleEnum::SUPPLY){//业务员
$store_id = Store::find()->select(['id'])->where(['code' => $admin->code])->column();
$query = ProductOrder::find()->alias('pd')->where(['in','pd.store_id',$store_id])->orderBy(['pd.id' => SORT_DESC]);
}else {//总后台
$query = ProductOrder::find()->alias('pd')->orderBy(['pd.id' => SORT_DESC]);
}
if (!empty($get['order_no'])) {//订单编号
$query->andWhere(['pd.order_no' => $get['order_no']]);
}
$query->joinWith(['prescription' => function ($p) use ($good_name) {
$p->alias('p');
if (!empty($good_name)) {//商品名称
$p->where(['like', 'p.content', $good_name]);
}
}]);
if (!empty($get['accept_name'])) {//收件人姓名
$query->where(['like', 'pd.express_name', $get['accept_name']]);
}
if (!empty($post['accept_tel'])) {//收件人电话
$query->where(['like', 'pd.express_mobile', $get['accept_tel']]);
}
$query->joinWith(['doctor' => function ($doc) use ($doctor) {
$doc->alias('doc');
if (!empty($doctor)) {//医生搜索
$doc->andWhere(['like', 'doc.name', $doctor]);
}
}]);
if (isset($get['status']) && is_numeric($get['status'])) {//产品订单状态
if ($get['status'] == 3) {
$query->andWhere(['pd.status' => [3, 6, 7]]);
} else {
$query->andWhere(['pd.status' => $get['status']]);
}
}
if (!empty($store)) {//门店
$query->andWhere(['pd.store_id' => $store]);
}
if (!empty($get['after_status'])) {//售后状态
$query->andWhere(['pd.refund_status' => $get['after_status']]);
}
if (!empty($type)) {
$query->andWhere(['pd.prescription_type' => $type]);
}
if (!empty($start_time) && !empty($end_time)) {
if ($start_time==$end_time){//筛选某一天
$time=FuncHelper::getDayBE($get['start_time']);
$end_time=$time[1];
}
$query->andWhere(['between', 'pd.created_at', $start_time,$end_time]);
}
$this->field = [
ProductOrder::class => [
'id', 'store_id','prescription_type', 'user_id', 'up_id', 'p_id', 'status', 'cancel_status', 'order_type', 'order_no', 'total_pay_price', 'type', 'items_price','market_price', 'process_price', 'treatement_price','address_id', 'status', 'trans_expenses', 'free_ship',
'cancel_time' => function ($pd) {
if($pd->cancel_time){
return date('Y-m-d H:i:s', $pd->cancel_time);
}
}, 'cancel_remark', 'refund_status',
'refund_time' => function ($pd) {
if($pd->refund_time){
return date('Y-m-d H:i:s', $pd->refund_time);
}
},
'store' => function ($d) {
return Store::find()->select(['id','drugstore_id','erp_id','plate_id','name','shouzimu','contact','mobile','offical_seal','code','position'])->where([
'id' => $d->store_id
])->one();
},
'drugstore' => function ($d) {
$drugstore_id = Store::find()->select(['drugstore_id'])->where([
'id' => $d->store_id
])->column();
return DrugStore::find()->select(['name'])->where(['in', 'id', $drugstore_id])->all();
},
'pay_time' => function ($m) {
if($m->pay_time){
return date('Y-m-d H:i:s', $m->pay_time);
}
},
'is_has' => function ($i) {
return $i->p_id ? '有处方' : '无处方';
},
'doctor' => 'doctor.name',
// 'good' => function ($model) {
// return $this->actionProductOrderDetail($model->id);
// },
'prescription' => function ($p) {
if($p->p_id){
$prescription = Prescription::find()->where([
'id' => $p->p_id,
'is_deleted' => 0
])->with(['pharmacistInfo','doctorInfo.depart'])->asArray()->one();
$content = Json::decode($prescription['content']);
$repice = $content['repice'];
if($prescription['prescription_type'] == 2){ //西药
foreach($repice as $k => $v){
$repice[$k]['content'] = Json::decode($v['content']);
}
} else {
$repiceContent = Json::decode($repice[0]['content']);
// foreach($repiceContent as $k=>$v){
// $repiceContent[$k]['content'] = Json::decode($v['content']);
// }
$repice[0]['content'] = $repiceContent;
}
$content['repice'] = $repice;
$prescription['content'] = $content;
}
return $prescription;
},
'address' => function ($m) {
return json_decode($m->address);
},
'created_at' => function ($mo) {
return date('Y-m-d H:i:s', $mo->created_at);
},
'express_name'=>function($e){
return $this->actionReceiveInfo($e->id,1);
},
'express_mobile'=>function($e){
return $this->actionReceiveInfo($e->id,2);
},
'express_region'=>function($e){
return $this->actionReceiveInfo($e->id,3);
},
'express_address'=>function($e){
return $this->actionReceiveInfo($e->id,4);
},
'patient' => 'userPatient.name',
'user' => 'user.nickname',
'product_order_items' => function ($m) {
return $this->actionProductOrderItem($m->id);
},
'patient_sex' => 'userPatient.sex',
'patient_age' => 'userPatient.age',
'patient_mobile' => 'userPatient.mobile',
'category' => 'prescription.category',
'productOrderRefund_status' => 'productOrderRefund.status',
'productOrderRefund_id' => function($m){
return $this->actionProductOrderRefund($m->id);
},
'service_price'=>function($m){
return $this->actionDaijianFei($m->id);
},
'is_decoct','decoct_price','express_no_id',
'delivery_method',
]
];
return $this->create($query, $get);
}
/**
* @doc-name 收获信息
* @doc-author huangyuling
*/
public function actionReceiveInfo($id,$type){
$info=ProductOrder::find()->where(['id'=>$id])->asArray()->one();
switch ($type){
case 1:
if ($info['delivery_method']==0){
return $info['express_name'];
}else{
$user_patient=UserPatient::find()->where(['id'=>$info['up_id']])->asArray()->one();
if (!$user_patient){
throw new Exception('患者信息不存在');
} return $user_patient['name'];
}
break;
case 2:
if ($info['delivery_method']==0){
return $info['express_name'];
}else{
$user_patient=UserPatient::find()->where(['id'=>$info['up_id']])->asArray()->one();
if (!$user_patient){
throw new Exception('患者信息不存在');
}
return $user_patient['mobile'];
}
break;
case 3:
if ($info['delivery_method']==0){
return $info['express_region'];
}else{
$store=Store::find()->where(['id'=>$info['store_id']])->with(['province','city'])->asArray()->one();
if (!$store){
throw new Exception('门店信息不存在');
}
return $store['province']['name'].$store['city']['name'];
}
break;
case 4:
if ($info['delivery_method']==0){
return $info['express_address'];
}else{
$store=Store::find()->where(['id'=>$info['store_id']])->asArray()->one();
if (!$store){
throw new Exception('门店信息不存在');
}
return $store['position'];
}
break;
default:
throw new Exception('类型错误');
}
}
/**
* @doc-name 退款申请ID
* @doc-return int id id
*/
public function actionProductOrderRefund($id)
{
$ProductOrderRefund=ProductOrderRefund::find()->select(['id','reason'])->where(['order_id'=>$id])->orderBy(['id'=>SORT_DESC])->one();
return $ProductOrderRefund;
}
/**
* @doc-name 取消商品(或产品)订单
* @doc-param int order_id 商品(或产品)订单id
* @doc-param int user_id 用户id
*/
public function actionGoodCancel()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['order_id', 'user_id'], 'required']
]);
$form = new ProductCancelForm();
return $form->cancel($post);
}
/**
* @doc-name 商品订单退款
* @doc-param int order_id 商品(或产品)订单id
* @doc-param int user_id 用户id
* @doc-param string reason 退款原因
* @doc-param string refund_images 退款图片 / optional
*/
public function actionGoodRefund()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['order_id', 'user_id', 'reason'], 'required']
]);
$form = new ProductRefundForm();
return $form->refund($post);
}
/**
* @doc-name 发货
* @doc-param int order_id 商品(或产品)订单id
*/
public function actionSendOperate()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
['order_id', 'required']
]);
$user = \Yii::$app->user->identity;
if ($user->role != UserRoleEnum::STORE_ADMIN) {
throw new Exception('您没有该门店权限');
}
$ProductOrder = ProductOrder::find()->where([
'store_id' => $user->store_id,
'id' => $post['order_id']
])->one();
if (!$ProductOrder) throw new Exception('产品订单不存在');
$Prescription=Prescription::find()->where(['id'=>$ProductOrder['p_id'],'is_deleted'=>0])->one();
if ($Prescription['status']!=1){
throw new Exception('处方未通过,不能发货');
}
$ProductOrder->is_send = 1;
$ProductOrder->send_time = date('Y-m-d H:i:s', time());
if (!$ProductOrder->saveOrFail()) {
throw new Exception('发货失败');
}
//订单发货3天后分账结算
// if($ProductOrder->type == 2){ //易票联支付的产品订单
// $config = \Yii::$app->params;
// $orderAutoSettlementTime = isset($config['product_order']['settlement_time']) ? $config['product_order']['settlement_time'] : 72*3600;
// $TIME=180;
// \Yii::$app->queue->delay($TIME)->push(new ProductOrderSendJob([
// 'orderId' => $ProductOrder->id
// ]));
// }
return ['发货成功'];
}
/**
* @doc-name 产品订单详情
* @doc-param int product_id 产品订单id
*/
public function actionProductDetail()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get, [
['product_id', 'required']
]);
$ProductOrder = ProductOrder::find()->where([
'id' => $get['product_id']
])->with(['expressNos', 'prescription', 'orderItems'])->asArray()->one();
if (!$ProductOrder) throw new Exception('产品订单不存在');
if ($ProductOrder['prescription']['prescription_type'] == 1) {
$SystemConfig = SystemConfig::findOne(['type' => 1]);
$ProductOrder['daijianfei'] = $SystemConfig['value'];
}
return $ProductOrder;
}
/**
* 订单物流详情
*/
public function actionExpress(){
$get = \Yii::$app->request->get();
$this->requestValidate($get, [
['order_id', 'required']
]);
$express = (new ExpressService())->detail($get['order_id']);
return $express;
}
/**
* @doc-name 处理处方快照
*/
public function actionProductOrderDetail($id = null)
{
$p_id = ProductOrder::find()->select(['p_id'])->where(['id' => $id])->column();
$prescription_type = Prescription::find()->select(['prescription_type'])->where(['id' => $p_id, 'is_deleted' => 0])->column();
if ($prescription_type[0] == 1 || $prescription_type[0] == 3) {//中药 配方颗粒
$content = Prescription::find()->where(['id' => $p_id, 'is_deleted' => 0])->one();
$recipe = json_decode($content['content'], true)['repice'];
$data['content'] = json_decode($recipe[0]['content']);
$data['deployment'] = $recipe[0]['deployment'];
$data['dosage'] = $recipe[0]['dosage'];
$data['consumption'] = $recipe[0]['consumption'];
$data['directions'] = $recipe[0]['directions'];
$data['usage'] = $recipe[0]['usage'];
$data['fufa_id'] = $recipe[0]['fufa_id'];
$data['volume'] = $recipe[0]['volume'];
$data['is_deepfry'] = $recipe[0]['is_deepfry'];
$data['cm_id'] = $recipe[0]['cm_id'];
$data['total_price'] = $recipe[0]['total_price'];
$data['remark'] = $recipe[0]['remark'];
return $data;
} else {//西药
$Prescription = Prescription::find()->where(['id' => $p_id, 'is_deleted' => 0])->one();
if (!$Prescription) throw new Exception('处方不存在');
$repice = json_decode($Prescription['content'], true)['repice'];
$data = [];
foreach ($repice as $v) {
$item = [
'id' => $v['id'],
'content' => json_decode($v['content']),
'drug_name' => json_decode($v['content'])->drug_name,
'source' => json_decode($v['content'])->source,
'function' => json_decode($v['content'])->function,
'usage' => json_decode($v['content'])->usage,
'specification' => json_decode($v['content'])->specification,
'instruction' => json_decode($v['content'])->instruction,
'image' => json_decode($v['content'])->image,
'number' => $v['number'],
'available_days' => $v['available_days'],
'total_price' => $v['total_price'],
'created_at' => $v['created_at'],
'type_id' => json_decode($v['content'])->type_id,
'time_id' => json_decode($v['content'])->time_id,
'frequency_id' => json_decode($v['content'])->frequency_id,
'unit_id' => json_decode($v['content'])->unit_id,
'usetime' => $v['usetime']['name'],
'frequency' => $v['frequency']['name'],
'grain_number' => $v['grain_number'],
'westUnit' => $v['westUnit']['name'],
'types' => $v['usetype']['name'], //药的使用方式
];
$data[] = $item;
}
return $data;
}
}
//商品订单的商品明细
public function actionProductOrderItem($id = null)
{
return ProductOrderItems::find()->with('drug')->where(['product_order_id' => $id])->asArray()->all();
}
/**
* @doc-name 导出产品订单
*/
public function actionExportProductOrder()
{
\Yii::$app->response->format = Response::FORMAT_RAW;
$params = \Yii::$app->request->get();
$parameter['header'] = ['易票联订单号','订单号','诊所名称', '商品名称', '规格', '厂家', '单价', '加工费', '诊疗费', '销售价', '采购价','总价', '运费', '医生', '订单状态', '售后状态', '下单时间', '收件人姓名', '电话', '地址', '支付时间'];
$parameter['data'] = ProductOrder::inventory($params,\Yii::$app->user->identity->store_id);
ExportService::ExportByCors($parameter);
}
/**
* @doc-name 代煎费
*/
public function actionDaijianFei($id=null)
{
$ProductOrder=ProductOrder::find()->where(['id'=>$id])->one();
if (!$ProductOrder)throw new Exception('产品订单不存在');
$Prescription=Prescription::findOne(['id'=>$ProductOrder['p_id'],'is_deleted'=>0]);
if ($Prescription['prescription_type'] == 1 || $Prescription['prescription_type']==3 ) {
$SystemConfig = SystemConfig::findOne(['type' => 1]);
return $SystemConfig['value'];
}else{
return '无';
}
}
}

View File

@@ -0,0 +1,234 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use common\enums\UserRoleEnum;
use common\helpers\FuncHelper;
use common\models\Prescription;
use common\models\ProductOrder;
use common\services\ExportService;
use yii\db\Exception;
use yii\helpers\Json;
use yii\web\Response;
/**
* @doc-module 处方
*/
class PrescriptionController extends BaseAdminController
{
/**
* @doc-name 处方列表
* @doc-param string prescription_no 处方编号 / optional
* @doc-param string name 患者 / optional
* @doc-param string doctor 开方医生 / optional
* @doc-param string clinical_diagnose 临床诊断 / optional
* @doc-param int status 处方状态0待审核1已通过2未通过3待使用4已使用5未使用6已失效7已初审 / optional
* @doc-return mixed @List{id,prescription_no-string-处方编号,name-string-患者,sex-int-性别,clinical_diagnose-string-临床诊断,doctor-string-开方医生,doctor_sign-string-医生签名,pharmacist-string-审核药师,pharmacist_view_time-string-审核时间,patient_mobile-string-患者电话,created_at-int-开方时间,status-int-处方状态0待审核1已通过2未通过3待使用4已使用5未使用6已失效7已初审,is_get-int-是否取药0否1是,prescription_type-int-1中药处方2西药处方3颗粒药处方,category-int-类别1自费2医保,is_pay-int-是否支付0否1是,pay_time-string-支付时间,pay_type-int-支付类型1微信2支付宝3银行卡4其他,type-int-类型1普通方2常用方,@OrderInfo{platform_id-int-平台id,platform_store_id-int-平台门店id,platform_order_id-int-平台订单ID,drugstore_id-string-仓库id,order_no-string-产品顶单号,p_id-int-处方id,order_type-int-订单类型1处方订单2商城订单3商城处方订单,type-int-支付类型1微信2支付宝3银行卡4其他,address-string-地址,is_pay-int-是否支付0否1是,total_pay_price-float-支付金额,free_ship-int-是否包邮0否1是,trans_expenses-float-运费(默认包邮),pay_method-int-支付方式1线上2线下,status-int-产品订单状态0未支付1待发货2待收货3已完成}} 处方列表
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionList()
{
$get = \Yii::$app->request->get();
$admin=\Yii::$app->user->identity;
$start_time=strtotime($get['start_time'].' '.'00:00:00');
$end_time=strtotime($get['end_time'].' '.'23:59:59');
if ($admin->role==UserRoleEnum::STORE_ADMIN){//门店
$query = Prescription::find()->where([
'store_id' => $admin->store_id,
'is_deleted' => 0,
])->orderBy(['id'=>SORT_DESC]);
}else{
$query = Prescription::find()->where([
'is_deleted' => 0
])->orderBy(['id'=>SORT_DESC]);
}
$name = $get['name'];
$doctor = $get['doctor'];
if (!empty($get['prescription_no'])) {//处方编号
$query->andWhere(['prescription_no' => $get['prescription_no']]);
}
if (!empty($name)) {//患者
$query->joinWith(['userPatient' => function ($u) use ($name) {
$u->where([
'like', 'name', $name
]);
}]);
}
if (!empty($doctor)) {//开方医生
$query->joinWith(['doctorInfo' => function ($d) use ($doctor) {
$d->where([
'like', 'name', $doctor
]);
}]);
}
if (!empty($get['clinical_diagnose'])) {//临床诊断
$query->andWhere(['like', 'yii_prescription.clinical_diagnose', $get['clinical_diagnose']]);
}
if (!empty($get['status'])) {//处方状态
$query->andWhere(['yii_prescription.status' => $get['status']]);
}
if (!empty($get['is_dispense'])) {//是否配药
$query->andWhere(['yii_prescription.is_dispense' => $get['is_dispense']]);
}
if (!empty($get['start_time']) && !empty($get['end_time'])){
if ($start_time==$end_time){//筛选某一天
$time=FuncHelper::getDayBE($get['start_time']);
$end_time=$time[1];
}
$query->andWhere(['between','yii_prescription.created_at',$start_time,$end_time]);
}
$this->field = [
Prescription::class => [
'id', 'prescription_no','online_prescription_no','valid_hours','is_online',
'content' => function ($p) {
$repice = Json::decode($p->content, true)['repice'];
return $repice;
},
'name' => 'userPatient.name',
'sex' => 'userPatient.sex',
'patient_age' => 'userPatient.age',
'dept' => 'doctorInfo.depart.name',
'patient_mobile' => 'userPatient.mobile',
'clinical_diagnose', 'doctor_order', 'prescription_type', 'category', 'doctor_sign',
'doctor' => 'doctorInfo.name',
'status', 'pharmacist' => 'pharmacistInfo.name', 'pharmacist_view_time'=>function($m){
return date('Y-m-d H:i:s',$m->pharmacist_view_time);
},
'is_pay', 'pay_type', 'pay_time', 'type','register_id','total_pay_price','cancel_status','cancel_time','cancel_remark','refund_status','refund_time','auto_expire_time',
'is_get' => function ($model) {
return ProductOrder::find()->select('is_pay')->where([
'p_id' => $model->id
])->column();
},
'order_info' => function ($q) {
return ProductOrder::find()->where([
'p_id' => $q->id
])->one();
}, 'created_at' => function ($m) {
return date('Y-m-d H:i:s', $m->created_at);
},
]
];
return $this->create($query, $get);
}
/**
* @doc-name 打印pdf
*/
public function actionPdf()
{
$prescription = \Yii::$app->request->post('prescription');
$mpdf = new \Mpdf\Mpdf([
'mode' => 'UTF-8', 'format' => 'A4', 'default_font_size' => 15, 'default_font' => '', 'margin_left' => 20, 'margin_right' => 20]);
$mpdf->autoScriptToLang = true;//支持中文设置
$mpdf->autoLangToFont = true;//支持中文设置
$mpdf->WriteHTML($prescription);
$path = 'FILE_UPLOAD' . date('YmdHis') . '_' . mt_rand(1, 5) . '.pdf';
$mpdf->Output();//直接在页面显示pdf页面内容
//$mpdf->Output($path,'f');//保存pdf文件到指定目录
}
/**
* @doc-name 处方详情
* @doc-param int id 处方id
*/
public function actionPrescriptionDetail()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get,[
['id','required']
]);
$Prescription= Prescription::find()->alias('p')->where([
'p.id'=>$get['id'],
'p.is_deleted' => 0
])->with(['register','store'])->joinWith(['userPatient'])->asArray()->one();
if (!$Prescription) throw new Exception('处方不存在');
if ( $Prescription['prescription_type']== 1 || $Prescription['prescription_type'] == 3) {//中药 配方颗粒
$content=$Prescription['content'];
$recipe = json_decode($content, true)['repice'];
$data['content']= json_decode($recipe[0]['content']);
$data['deployment']=$recipe[0]['deployment'];
$data['dosage']=$recipe[0]['dosage'];
$data['consumption']=$recipe[0]['consumption'];
$data['directions']=$recipe[0]['directions'];
$data['usage']=$recipe[0]['usage'];
$data['fufa_id']=$recipe[0]['fufa_id'];
$data['volume']=$recipe[0]['volume'];
$data['is_deepfry']=$recipe[0]['is_deepfry'];
$data['cm_id']=$recipe[0]['cm_id'];
$data['total_price']=$recipe[0]['total_price'];
$data['remark']=$recipe[0]['remark'];
} else {//西药
$repice = json_decode($Prescription['content'], true)['repice'];
$data = [];
foreach ($repice as $v) {
$item = [
'id' => $v['id'],
'content' => json_decode($v['content']),
'drug_name' => json_decode($v['content'])->drug_name,
'source' => json_decode($v['content'])->source,
'function' => json_decode($v['content'])->function,
'usage' => json_decode($v['content'])->usage,
'specification' => json_decode($v['content'])->specification,
'instruction' => json_decode($v['content'])->instruction,
'image' => json_decode($v['content'])->image,
'number' => $v['number'],
'available_days' => $v['available_days'],
'total_price' => $v['total_price'],
'created_at' => $v['created_at'],
'type_id' => json_decode($v['content'])->type_id,
'time_id' => json_decode($v['content'])->time_id,
'frequency_id' => json_decode($v['content'])->frequency_id,
'unit_id' => json_decode($v['content'])->unit_id,
'usetime' => $v['usetime']['name'],
'frequency' => $v['frequency']['name'],
'grain_number' => $v['grain_number'],
'westUnit' => $v['westUnit']['name'],
'types' => $v['usetype']['name'], //药的使用方式
];
$data[] = $item;
}
}
$ProductOrder=ProductOrder::find()->where([
'p_id'=>$get['id']
])->one();
return [
'content'=>$data,
'prescription'=>$Prescription,
'ProductOrder'=>$ProductOrder
];
}
/**
* @doc-name 导出处方
*/
public function actionExportPrescription()
{
// \Yii::$app->response->format = Response::FORMAT_RAW;
$params=\Yii::$app->request->get();
$parameter['header']=['订单号','医生','患者','订单状态','价格','是否取药','时间'];
$parameter['data']=Prescription::inventory($params,\Yii::$app->user->identity->store_id);
// $Name='处方记录';
// $class=new Prescription();
ExportService::ExportByCors($parameter);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use common\helpers\ArrayHelper;
use common\helpers\FuncHelper;
use common\models\Region;
use yii\db\Exception;
class RegionController extends BaseAdminController
{
/**
* @doc-name 快递费--地区列表
*/
public function actionRegionList()
{
$get = \Yii::$app->request->get();
$query = Region::find()->where(['level'=>1]);
$this->field = [
Region::class => [
'id', 'name', 'pid', 'level', 'express_fee'
]
];
return $this->create($query, $get);
}
/**
* @doc-name 编辑快递费
* @doc-param int id id
* @doc-param float express_fee 快递费
*/
public function actionEditFee()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['id', 'express_fee'], 'required'],
]);
$Region = Region::find()->where(['id' => $post['id']])->one();
if (!$Region) throw new Exception('地区不存在');
$Region->express_fee = $post['express_fee'];
if (!$Region->saveOrFail()) {
throw new Exception('修改失败');
};
return ['修改成功'];
}
/**
* @doc-name 地区列表
*/
public function actionAllRegionList()
{
$Region = Region::find()->asArray()->all();
return ArrayHelper::list_to_tree($Region, 'id', 'pid', 'children');
}
}

View File

@@ -0,0 +1,182 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use common\enums\UserRoleEnum;
use common\helpers\FuncHelper;
use common\models\DoctorService;
use common\models\Register;
use common\models\ServiceUser;
use yii\db\Exception;
class RegisterController extends BaseAdminController
{
/**
* @doc-name 挂号列表
* @doc-param string mobile 电话 / optional
* @doc-param string name 患者 / optional
* @doc-param string order_no 订单号 / optional
* @doc-param string doctor 医生 / optional
* @doc-return mixed @List{User{id,user_id,doctor-string-医生,user_patient-string-患者,created_at-string-挂号时间,patient_mobile-string-患者点电话,order_no-string-订单号,depart-int-科室} 用户列表
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionList()
{
$get = \Yii::$app->request->get();
$admin = \Yii::$app->user->identity;
if (!empty($get['start_time']) && !empty($get['end_time'])) {
$start_time = strtotime($get['start_time'] . ' ' . '00:00:00');
$end_time = strtotime($get['end_time'] . ' ' . '23:59:59');
}
if ($admin->role == UserRoleEnum::STORE_ADMIN) {//门店
$query = Register::find()->alias('r')->where([
'r.store_id' => $admin->store_id,
'r.is_delete' => 0,
])->orderBy(['r.id' => SORT_DESC]);
} else {
$query = Register::find()->alias('r')->where([
'r.is_delete' => 0
])->orderBy(['r.id' => SORT_DESC]);
}
$patient = $get['patient_name'];
$mobile = $get['mobile'];
$doctor = $get['doctor_name'];
$query->joinWith(['patient' => function ($p) use ($patient, $mobile) {
$p->alias('p');
if (!empty($patient)) {//患者
$p->andWhere(['like', 'p.name', $patient]);
}
if (!empty($mobile)) {//手机号
$p->andWhere(['p.mobile' => $mobile]);
}
}]);
$query->joinWith(['doctor' => function ($d) use ($doctor) {
$d->alias('d');
if (!empty($doctor)) {//医生
$d->andWhere(['like', 'd.name', $doctor]);
}
}]);
if (!empty($get['order_no'])) {//订单号
$query->andWhere(['like', 'order_no', $get['order_no']]);
}
if (!empty($start_time) && !empty($end_time)) {
if ($start_time == $end_time) {//筛选当天
$time = FuncHelper::getDayBE($get['start_time']);
$end_time = $time[1];
}
$query->andWhere(['between', 'r.created_at', $start_time, $end_time]);
}
$this->field = [
Register::class => [
'id', 'doctor' => 'doctor.name', 'user_patient' => 'patient.name', 'patient_mobile' => 'patient.mobile', 'user_id', 'order_no', 'depart' => 'depart.name', 'order_number', 'price', 'is_pay', 'status', 'refuse_reason', 'pay_type',
'pay_time' => function ($p) {
if (!empty($p->pay_time)) {
return date('Y-m-d H:i:s', $p->pay_time);
} else {
return '无';
}
},
'is_cancel', 'cancel_status', 'cancel_time', 'cancel_remark', 'refund_status', 'refund_time', 'created_at',
'patient_age' => 'patient.age'
]
];
return $this->create($query, $get);
}
/**
* @doc-name 挂号设置
* @doc-param int su_id 医生ID
* @doc-param int status 1开启0不开启
* @doc-param float price 价格 /
*/
public function actionRegisterSet()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get, [
[['su_id', 'status'], 'required'],
]);
$ServiceUser = ServiceUser::find()->where(['id' => $get['su_id'], 'is_delete' => 0])->one();
if (!$ServiceUser) throw new Exception('医生不存在');
$DoctorService = DoctorService::findOne(['su_id' => $get['su_id']]);
if (!$DoctorService) {
throw new Exception('医生基本信息不存在');
}
if ($get['status'] == 1) {
$DoctorService->register_status = 1;
$DoctorService->register_price = $get['price'] ?? 0;
$DoctorService->saveOrFail();
return ['已开启挂号服务'];
} else {
$DoctorService->register_status = 0;
$DoctorService->register_price = 0;
$DoctorService->saveOrFail();
return ['已关闭挂号服务'];
}
}
/**
* @doc-name 挂号费汇总
*/
public function actionRegisterStatistic()
{
$get = \Yii::$app->request->get();
if (!empty($get['start_time']) && !empty($get['end_time'])) {
$start_time = strtotime($get['start_time'] . ' ' . '00:00:00');
$end_time = strtotime($get['end_time'] . ' ' . '23:59:59');
}
$user = \Yii::$app->user->identity;
$register_query = Register::find()->alias('re');
$month_start = strtotime(date('Y-m-01 00:00:00'));
$month_end = strtotime(date('Y-m-t 23:59:59'));
if (!empty($start_time) && !empty($end_time)) {
$register_data = ['between', 're.created_at', $start_time, $end_time];
} else {
$register_data = ['between', 're.created_at', $month_start, $month_end];
}
if ($user->role == UserRoleEnum::STORE_ADMIN) {
$register_query->where(['re.store_id' => $user->store_id]);
}
//挂号
$register_price = $register_query
->andWhere([
'and',
['=', 'is_pay', 1],
['<>', 'is_cancel', 1],
['<>', 're.refund_status', 1],
['=','is_delete' , 0]
])
->andWhere([
'and',
['<>', 're.status', 0],
['<>', 're.status', 4],
['<>', 're.status', 7],
])
->andWhere($register_data ?? '')->sum('price');
return [
'register_price' => $register_price ?? 0,
];
}
}

View File

@@ -0,0 +1,141 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use admin\models\forms\drug\AgreeForm;
use common\models\BaseConfig;
use common\models\SystemConfig;
use yii\db\Exception;
/**
* @doc-module 设置
*/
class SetController extends BaseAdminController
{
/**
* @doc-name 协议列表
* @doc-return mixed @List{id,end-int-1用户端2服务端 ,type-int-类型1服务协议2隐私政策3其他,desc-string-描述,content-string-内容,change_at-string-变更时间,status-int-是否删除0否1是,created_at-int-创建时间} 协议列表
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionAgreeList()
{
$get= \Yii::$app->request->get();
$query=BaseConfig::find()->where([
'status'=>0
]);
$this->field=[
BaseConfig::class=>[
'id','type','desc','content','change_at'=>function($m){
return date('Y-m-d H:i:s',$m->change_at);
},
'status','end',
'created_at'=>function($model){
return date('Y-m-d H:i:s',$model->created_at);
}
]
];
return $this->create($query,$get);
}
/**
* @doc-name 删除协议
* @doc-param int id 协议ID
*/
public function actionAgreeDel()
{
$get= \Yii::$app->request->get();
$this->requestValidate($get,[
['id','required']
]);
$AgreeForm=new AgreeForm();
$AgreeForm->attributes=$get;
return $AgreeForm->del();
}
/**
* @doc-name 编译协议及新增协议
* @doc-desc 传id即为编辑
* @doc-param int id 协议ID / optional
* @doc-param string type 类型1服务协议2隐私政策3其他
* @doc-param string desc 描述 / optional
* @doc-param string content 内容
*/
public function actionAgreeSave()
{
$post = \Yii::$app->request->post();
$AgreeForm=new AgreeForm();
$AgreeForm->attributes=$post;
return $AgreeForm->save();
}
/**
* @doc-name 西药包邮
* @doc-desc 传id即为编辑
* @doc-param string name name
* @doc-param string rule 规则
* @doc-param string value 值
*/
public function actionFreeShip()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['name','required'],
['rule','required'],
['value','required'],
]);
$SystemConfig=SystemConfig::find()->where([
'config_type'=>2,
'type'=>2
])->one();
if (!$SystemConfig){
throw new Exception('西药包邮配置不存在');
}
$SystemConfig->name=$post['name'];
$SystemConfig->rule=$post['rule'];
$SystemConfig->value=$post['value'];
$SystemConfig->saveOrFail();
return ['设置成功'];
}
/**
* 小程序版本
*/
public function actionXcxVersion(){
$SystemConfig=SystemConfig::find()->where([
'config_type'=>3,
])->one();
if (!$SystemConfig){
throw new Exception('小程序版本配置不存在');
}
return $SystemConfig;
}
/**
* 小程序版本设置
*/
public function actionXcxVersionSet(){
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['value','required'],
]);
$SystemConfig=SystemConfig::find()->where([
'config_type'=>3,
])->one();
if (!$SystemConfig){
throw new Exception('小程序版本配置不存在');
}
$SystemConfig->value=$post['value'];
$SystemConfig->saveOrFail();
return ['设置成功'];
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,405 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use common\enums\UserRoleEnum;
use common\models\Admin;
use common\models\ProductOrder;
use common\models\Reconciliation;
use common\models\Store;
use yii\db\Exception;
/**
* @doc-module 业务员
*/
class SupplyController extends BaseAdminController
{
/**
* @doc-name 列表
* @doc-param int type 1销售数据2产品数据
* @doc-param int sort 1诊所2业务员3省4市
* @doc-param string start_time / optional
* @doc-param string end_time / optional
* @doc-param string limit_time 1当月2上月3累计 / optional
* @doc-return mixed @List{supply-string-业务员,position-string-诊所位置,mobile-string-诊所电话,offical_seal-string-公章,code-string-推广码,sale_price-float-销售金额,drug_number-string-药品编码,drug_name-string-药名}
*/
public function actionList()
{
$get = \Yii::$app->request->get();
$admin = \Yii::$app->user->identity;
$this->requestValidate($get, [
['type', 'required'],
]);
$search = $get['search'];
$sort = $get['sort'];
$limit_time = $get['limit_time'];
if ($admin->role == UserRoleEnum::PROVINCE_DAI) {//省代
switch ($get['type']) {
case 1:
$query = Store::find()->alias('s')->where(['s.is_delete' => 0, 's.province_id' => $admin->province_id]);
break;
case 2:
$query = Reconciliation::find()->orderBy(['id' => SORT_DESC])->alias('r')->where(['r.status' => 1])->joinWith(['store' => function ($store) use ($admin) {
$store->alias('st');
$store->where(['st.province_id' => $admin->province_id]);
}]);
break;
default:
throw new Exception('参数错误');
}
} elseif ($admin->role == UserRoleEnum::CITY_DAI) {//市代
switch ($get['type']) {
case 1:
$query = Store::find()->alias('s')->where(['s.is_delete' => 0, 's.city_id' => $admin->city_id]);
break;
case 2:
$query = Reconciliation::find()->orderBy(['id' => SORT_DESC])->alias('r')->where(['r.status' => 1])->joinWith(['store' => function ($store) use ($admin) {
$store->alias('st');
$store->where(['st.city_id' => $admin->city_id]);
}]);
break;
default:
throw new Exception('参数错误');
}
} elseif ($admin->role == UserRoleEnum::SUPPLY) {//业务员
switch ($get['type']) {
case 1:
$query = Store::find()->alias('s')->where(['s.code' => $admin->code, 's.is_delete' => 0]);
break;
case 2:
$query = Reconciliation::find()->orderBy(['id' => SORT_DESC])->alias('r')->where(['r.status' => 1])->joinWith(['store' => function ($store) use ($admin) {
$store->where(['uid' => $admin->uid]);
}]);
break;
default:
throw new Exception('参数错误');
}
} else {
throw new Exception('角色错误');
}
switch ($get['type']) {
case 1:
if ($limit_time == 1) {
$start_time = strtotime(date('Y-m-01 00:00:00'));
$end_time = strtotime(date('Y-m-t 23:59:59'));
$query->joinWith(['reconciliation' => function ($r) use ($start_time, $end_time) {
$r->alias('re');
$r->where(['re.status' => 1])->andWhere([
'between', 're.pay_time', $start_time, $end_time]);
}]);
}
if ($limit_time == 2) {
$now = new \DateTime();
$now->modify('first day of last month');
$start_time = $now->format('Y-m-01 00:00:00');
$end_time = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
$query->joinWith(['reconciliation' => function ($r) use ($start_time, $end_time) {
$r->alias('re');
$r->where(['re.status' => 1])->andWhere([
'between', 're.pay_time', strtotime($start_time), strtotime($end_time)]);
}]);
}
if (!empty($sort)) {
switch ($sort) {
case 1:
if (!empty($search)) $query->andWhere(['like', 's.name', $search]);
break;
case 2:
if (!empty($search)) {
$query->joinWith(['admin' => function ($a) use ($search) {
$a->andWhere(['like', 'username', $search]);
}]);
}
break;
case 3:
if (!empty($search)) {
$query->joinWith(['province' => function ($p) use ($search) {
$p->alias('p')->where(['like', 'p.name', $search]);
}]);
}
break;
case 4:
if (!empty($search)) {
$query->joinWith(['city' => function ($c) use ($search) {
$c->alias('c')->where(['like', 'c.name', $search]);
}]);
}
break;
default:
throw new Exception('参数错误');
}
}
$this->field = [
Store::class => [
'id', 'name', 'position', 'mobile', 'offical_seal', 'code', 'uid',
'supply' => 'admin.username',
'province' => 'province.name',
'city' => 'city.name',
'city_id',
'province_id',
'sale_price' => function ($s) {
return $this->actionSalePrice($s->id);
}
]
];
return $this->create($query, $get);
case 2:
if ($limit_time == 1) {
$start_time = strtotime(date('Y-m-01 00:00:00'));
$end_time = strtotime(date('Y-m-t 23:59:59'));
$query->andWhere(['between', 'r.pay_time', $start_time, $end_time]);
}
if ($limit_time == 2) {
$now = new \DateTime();
$now->modify('first day of last month');
$start_time = $now->format('Y-m-01 00:00:00');
$end_time = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
$query->andWhere(['between', 'r.pay_time', strtotime($start_time), strtotime($end_time)]);
}
if (!empty($get['start_time']) && !empty($get['end_time'])) {
$query->andWhere(['between', 'r.pay_time', strtotime($get['start_time']), strtotime($get['end_time'])]);
}
if (!empty($sort)) {
switch ($sort) {
case 1:
$query->joinWith(['store' => function ($s) use ($search) {
$s->alias('s');
$s->andWhere([
'or',
['like', 's.name', $search],
['like', 's.shouzimu', $search],
]);
}]);
break;
case 2:
if (!empty($search)) {
$query->joinWith(['store' => function ($s) use ($search) {
$s->joinWith(['admin' => function ($a) use ($search) {
$a->andWhere(['like', 'username', $search]);
}]);
}]);
}
break;
case 3:
if (!empty($search)) {
$query->joinWith(['store' => function ($s) use ($search) {
$s->joinWith(['province' => function ($ss) use ($search) {
$ss->alias('pro');
$ss->andWhere(['like', 'pro.name', $search]);
}]);
}]);
}
break;
case 4:
if (!empty($search)) {
$query->joinWith(['store' => function ($s) use ($search) {
$s->joinWith(['city' => function ($ct) use ($search) {
$ct->alias('city');
$ct->andWhere(['like', 'city.name', $search]);
}]);
}]);
}
break;
default:
throw new Exception('参数错误');
}
}
//
// $query->joinWith(['drug' => function ($d) use ($search) {
// $d->alias('d');
// $d->andWhere([
// 'or',
// ['like', 'd.drug_name', $search],
// ['like', 'd.pinyin_simple', $search],
// ]);
// }]);
if (!empty($search)) {
if ($search == 1) {
$query->andWhere(['r.drug_type' => [1, 3]]);
} else {
$query->andWhere(['r.drug_type' => [2, 4]]);
}
}
$this->field = [
Reconciliation::class => [
'id', 'order_id', 'store_id', 'pay_time' => function ($m) {
return date('Y-m-d H:i:s', $m->pay_time);
},
'drug_id', 'drug_type', 'number', 'total_buy_price', 'total_price', 'status',
'drug_number' => 'drug.drug_number',
'drug_name' => 'drug.drug_name',
'store_number' => 'productOrder.store.id',
'store' => 'store.name',
'supply' => 'store.admin.username',
'province' => 'store.province.name',
'city' => 'store.city.name',
'province_id' => 'store.province_id',
'city_id' => 'store.city_id',
]
];
return $this->create($query, $get);
default:
throw new Exception('参数错误');
}
}
public function actionSalePrice($store)
{
$Reconciliation = Reconciliation::find()->where(['store_id' => $store, 'status' => 1])->sum('total_price');
return $Reconciliation ?? 0;
}
/**
* @doc-name 按照诊所统计
* @doc-param string start_time 起始时间
* @doc-param string end_time 终止时间
* @doc-param string limit_time 1当月2上月3累计 / optional
*/
public function actionStoreStatics()
{
$admin = \Yii::$app->user->identity;
$get = \Yii::$app->request->get();
$limit_time = $get['limit_time'];
if (!empty($get['start_time']) && !empty($get['end_time'])) {
$data = ['between', 'pay_time', strtotime($get['start_time']), strtotime($get['end_time'])];
}
if ($limit_time == 1) {
$start_time = strtotime(date('Y-m-01 00:00:00'));
$end_time = strtotime(date('Y-m-t 23:59:59'));
$data = ['between', 'pay_time', $start_time, $end_time];
}
if ($limit_time == 2) {
$now = new \DateTime();
$now->modify('first day of last month');
$start_time = $now->format('Y-m-01 00:00:00');
$end_time = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
$data = ['between', 'pay_time', strtotime($start_time), strtotime($end_time)];
}
if (!empty($get['start_time']) && !empty($get['end_time'])) {
$data = ['between', 'pay_time', strtotime($get['start_time']), strtotime($get['end_time'])];
}
if ($admin->role == UserRoleEnum::PROVINCE_DAI) {//省代
$store_id = Store::find()->select(['id'])->where(['province_id' => $admin->province_id])->column();
$total_price = Reconciliation::find()->where(['in', 'store_id', $store_id])->andWhere(['status' => 1])->andWhere($data ?? '')->sum('total_price');
$total_buy_price= Reconciliation::find()->where(['in', 'store_id', $store_id])->andWhere(['status' => 1])->andWhere($data ?? '')->sum('total_buy_price');
$store = Store::find()->where(['province_id' => $admin->province_id])->count();
} elseif ($admin->role == UserRoleEnum::CITY_DAI) {//市代
$store_id = Store::find()->select(['id'])->where(['city_id' => $admin->city_id])->column();
$total_price = Reconciliation::find()->where(['in', 'store_id', $store_id])->andWhere(['status' => 1])->andWhere($data ?? '')->sum('total_price');
$total_buy_price= Reconciliation::find()->where(['in', 'store_id', $store_id])->andWhere(['status' => 1])->andWhere($data ?? '')->sum('total_buy_price');
$store = Store::find()->where(['city_id' => $admin->city_id])->count();
} elseif ($admin->role == UserRoleEnum::SUPPLY) {//业务员
$store_id = Store::find()->select(['id'])->where(['code' => $admin->code])->column();
$total_price = Reconciliation::find()->where(['in', 'store_id', $store_id])->andWhere(['status' => 1])->andWhere($data ?? '')->sum('total_price');
$total_buy_price= Reconciliation::find()->where(['in', 'store_id', $store_id])->andWhere(['status' => 1])->andWhere($data ?? '')->sum('total_buy_price');
$store = Store::find()->where(['code' => $admin->code])->count();
} else {
throw new Exception('角色错误');
}
return [
'store_num' => $store ?? 0,
'total_price' => $total_price ?? 0,
'total_buy_price' => $total_buy_price ?? 0,
];
}
/**
* @doc-name 按照产品统计
* @doc-param string start_time 起始时间
* @doc-param string end_time 终止时间
* @doc-param string limit_time 1当月2上月3累计 / optional
*/
public function actionProductStatics()
{
$get = \Yii::$app->request->get();
$admin = \Yii::$app->user->identity;
$limit_time = $get['limit_time'];
if ($limit_time == 1) {
$start_time = strtotime(date('Y-m-01 00:00:00'));
$end_time = strtotime(date('Y-m-t 23:59:59'));
$data = ['between', 'pay_time', $start_time, $end_time];
}
if ($limit_time == 2) {
$now = new \DateTime();
$now->modify('first day of last month');
$start_time = $now->format('Y-m-01 00:00:00');
$end_time = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
$data = ['between', 'pay_time', strtotime($start_time), strtotime($end_time)];
}
if (!empty($get['start_time']) && !empty($get['end_time'])) {
$data = ['between', 'pay_time', strtotime($get['start_time']), strtotime($get['end_time'])];
}
if ($admin->role == UserRoleEnum::PROVINCE_DAI) {//省代
$store_id = Store::find()->select(['id'])->where(['province_id' => $admin->province_id])->column();
$all_sale = Reconciliation::find()->alias('r')->andWhere([
'and',
['r.status' => 1],
['in', 'r.store_id', $store_id]
])->andWhere($data ?? '')->sum('number');
$all_total_price = Reconciliation::find()->alias('r')->andWhere([
'and',
['r.status' => 1],
['in', 'r.store_id', $store_id]
])->andWhere($data ?? '')->sum('total_price');
} elseif ($admin->role == UserRoleEnum::CITY_DAI) {//市代
$store_id = Store::find()->select(['id'])->where(['city_id' => $admin->city_id])->column();
$all_sale = Reconciliation::find()->alias('r')->andWhere([
'and',
['r.status' => 1],
['in', 'r.store_id', $store_id]
])->andWhere($data ?? '')->sum('number');
$all_total_price = Reconciliation::find()->alias('r')->andWhere([
'and',
['r.status' => 1],
['in', 'r.store_id', $store_id]
])->andWhere($data ?? '')->sum('total_price');
} elseif ($admin->role == UserRoleEnum::SUPPLY) {//业务员
$store_id = Store::find()->select(['id'])->where(['code' => $admin->code])->column();
$all_sale = Reconciliation::find()->alias('r')->andWhere([
'and',
['r.status' => 1],
['in', 'r.store_id', $store_id]
])->andWhere($data ?? '')->sum('number');
$all_total_price = Reconciliation::find()->alias('r')->andWhere([
'and',
['r.status' => 1],
['in', 'r.store_id', $store_id]
])->andWhere($data ?? '')->sum('total_price');
} else {
throw new Exception('角色错误');
}
return [
'all_sale' => $all_sale ?? 0,
'all_total_price' => $all_total_price ?? 0,
];
}
}

View File

@@ -0,0 +1,226 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\controllers\AuthController;
use common\enums\UserRoleEnum;
use common\jobs\SyncHospitalJob;
use common\models\DrugStoreDrug;
use common\models\DrugStoreRelations;
use common\models\Store;
use common\services\PlatformService;
use linslin\yii2\curl\Curl;
use yii\db\Exception;
class SyncController extends BaseAdminController
{
/**
* @doc-name 同步所有的门店门店----总后台同步
*/
public function actionSyncStore()
{
$admin = \Yii::$app->user->identity;
if ($admin->role != UserRoleEnum::SUPER_ADMIN) {
throw new Exception('非超管,您不能同步药品');
}
$DrugStoreDrug_chinese = DrugStoreDrug::find()->select(['drug_id', 'price', 'market_price', 'status'])->where(['type' => 1])->asArray()->all();
$DrugStoreDrug_west = DrugStoreDrug::find()->select(['drug_id', 'price', 'market_price', 'status'])->where(['type' => 2])->asArray()->all();
$DrugStoreDrug_grain = DrugStoreDrug::find()->select(['drug_id', 'price', 'market_price', 'status'])->where(['type' => 3])->asArray()->all();
$DrugStoreDrug_zongcheng = DrugStoreDrug::find()->select(['drug_id', 'price', 'market_price', 'status'])->where(['type' => 4])->asArray()->all();
$store = Store::find()->select(['id', 'z_buy_percent', 'z_sale_percent', 'g_bug_percent', 'g_sale_percent'])->where(['is_delete' => 0])->all();
$t = \Yii::$app->db->beginTransaction();
try {
foreach ($store as $value) {//中药
foreach ($DrugStoreDrug_chinese as $val) {
$Drug = DrugStoreRelations::find()->where([
'store_id' => $value['id'],
'drug_id' => $val['drug_id']
])->one();
if (!$Drug) {
$DrugStoreRelations = new DrugStoreRelations();
$DrugStoreRelations->store_id = $value['id'];
$DrugStoreRelations->drug_id = $val['drug_id'];
$DrugStoreRelations->price = bcdiv(bcmul($val['price'], $value['z_sale_percent']??100, 4), 100, 4);
$DrugStoreRelations->buy_price = bcdiv(bcmul($val['market_price'], $value['z_buy_percent']??100, 4), 100, 4);
$DrugStoreRelations->status = $val['status'];
$DrugStoreRelations->saveOrFail();
}
}
}
foreach ($store as $value) {//西药
foreach ($DrugStoreDrug_west as $v) {
$DrugStore = DrugStoreRelations::find()->where([
'store_id' => $value['id'],
'drug_id' => $v['drug_id']
])->one();
if (!$DrugStore) {
$DrugStoreRelations = new DrugStoreRelations();
$DrugStoreRelations->store_id = $value['id'];
$DrugStoreRelations->drug_id = $v['drug_id'];
$DrugStoreRelations->price = $v['price'];
$DrugStoreRelations->buy_price = $v['market_price'] ?? $v['price'];
$DrugStoreRelations->status = $v['status'];
$DrugStoreRelations->saveOrFail();
}
}
}
foreach ($store as $value) {//配方
foreach ($DrugStoreDrug_grain as $vv) {
$DrugStoreRelations = DrugStoreRelations::find()->where([
'store_id' => $value['id'],
'drug_id' => $vv['drug_id']
])->one();
if (!$DrugStoreRelations) {
$DrugStoreRelations = new DrugStoreRelations();
$DrugStoreRelations->store_id = $value['id'];
$DrugStoreRelations->drug_id = $vv['drug_id'];
$DrugStoreRelations->price = bcdiv(bcmul($vv['price'], $value['g_sale_percent']??100, 4), 100, 4);
$DrugStoreRelations->buy_price = bcdiv(bcmul($vv['market_price'], $value['g_bug_percent']??100, 4), 100, 4);
$DrugStoreRelations->status = $vv['status'];
$DrugStoreRelations->saveOrFail();
}
}
}
foreach ($store as $value) {//中成药
foreach ($DrugStoreDrug_zongcheng as $vv) {
$DrugStoreRelations_z = DrugStoreRelations::find()->where([
'store_id' => $value['id'],
'drug_id' => $vv['drug_id']
])->one();
if (!$DrugStoreRelations_z) {
$DrugStoreRelations = new DrugStoreRelations();
$DrugStoreRelations->store_id = $value['id'];
$DrugStoreRelations->drug_id = $vv['drug_id'];
$DrugStoreRelations->price = $vv['price'];
$DrugStoreRelations->buy_price = $vv['market_price'] ?? $vv['price'];
$DrugStoreRelations->status = $vv['status'];
$DrugStoreRelations->saveOrFail();
}
}
}
} catch (\Exception $e) {
$t->rollBack();
throw new Exception($e->getMessage());
}
$t->commit();
return ['同步成功'];
}
/**
* @doc-name 同步互医
*/
public function actionSyncHospital()
{
$type=4;
$admin=\Yii::$app->user->identity;
\Yii::$app->queue->delay(0)->push(new SyncHospitalJob([
'admin_id'=>$admin->uid,
'type'=>$type,
]));
}
/**
* @doc-name 同步单个门店
* @doc-param int store_id 门店ID
*/
public function actionSyncUnitStore()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get, [
['store_id', 'required']
]);
$DrugStoreDrug_chinese = DrugStoreDrug::find()->select(['drug_id', 'price', 'market_price', 'status'])->where(['type' => 1])->asArray()->all();
$DrugStoreDrug_west = DrugStoreDrug::find()->select(['drug_id', 'price', 'market_price', 'status'])->where(['type' => 2])->asArray()->all();
$DrugStoreDrug_grain = DrugStoreDrug::find()->select(['drug_id', 'price', 'market_price', 'status'])->where(['type' => 3])->asArray()->all();
$DrugStoreDrug_zongcheng = DrugStoreDrug::find()->select(['drug_id', 'price', 'market_price', 'status'])->where(['type' => 4])->asArray()->all();
$store = Store::find()->select(['id', 'z_buy_percent', 'z_sale_percent', 'g_bug_percent', 'g_sale_percent'])->where(['id' => $get['store_id'], 'is_delete' => 0])->one();
if (!$store) throw new Exception('门店不存在');
$t = \Yii::$app->db->beginTransaction();
try {
//中药
foreach ($DrugStoreDrug_chinese as $val) {
$Drug = DrugStoreRelations::find()->where([
'store_id' => $get['store_id'],
'drug_id' => $val['drug_id']
])->one();
if (!$Drug) {
$DrugStoreRelations = new DrugStoreRelations();
$DrugStoreRelations->store_id = $get['store_id'];
$DrugStoreRelations->drug_id = $val['drug_id'];
$DrugStoreRelations->price = bcdiv(bcmul($val['price'], $store['z_sale_percent']??100, 4), 100, 4);
$DrugStoreRelations->buy_price = bcdiv(bcmul($val['market_price'], $store['z_buy_percent']??100, 4), 100, 4);
$DrugStoreRelations->status = $val['status'];
$DrugStoreRelations->saveOrFail();
}
}
//西药
foreach ($DrugStoreDrug_west as $v) {
$DrugStore = DrugStoreRelations::find()->where([
'store_id' => $get['store_id'],
'drug_id' => $v['drug_id']
])->one();
if (!$DrugStore) {
$DrugStoreRelations = new DrugStoreRelations();
$DrugStoreRelations->store_id = $get['store_id'];
$DrugStoreRelations->drug_id = $v['drug_id'];
$DrugStoreRelations->price = $v['price'];
$DrugStoreRelations->buy_price = $v['market_price'] ?? $v['price'];
$DrugStoreRelations->status = $v['status'];
$DrugStoreRelations->saveOrFail();
}
}
//配方
foreach ($DrugStoreDrug_grain as $vv) {
$DrugStoreRelations = DrugStoreRelations::find()->where([
'store_id' => $get['store_id'],
'drug_id' => $vv['drug_id']
])->one();
if (!$DrugStoreRelations) {
$DrugStoreRelations = new DrugStoreRelations();
$DrugStoreRelations->store_id = $get['store_id'];
$DrugStoreRelations->drug_id = $vv['drug_id'];
$DrugStoreRelations->price = bcdiv(bcmul($vv['price'], $store['g_sale_percent']??100, 4), 100, 4);
$DrugStoreRelations->buy_price = bcdiv(bcmul($vv['market_price'], $store['g_bug_percent']??100, 4), 100, 4);
$DrugStoreRelations->status = $vv['status'];
$DrugStoreRelations->saveOrFail();
}
}
//中成药
foreach ($DrugStoreDrug_zongcheng as $vv) {
$DrugStoreRelations_z = DrugStoreRelations::find()->where([
'store_id' => $get['store_id'],
'drug_id' => $vv['drug_id']
])->one();
if (!$DrugStoreRelations_z) {
$DrugStoreRelations = new DrugStoreRelations();
$DrugStoreRelations->store_id = $get['store_id'];
$DrugStoreRelations->drug_id = $vv['drug_id'];
$DrugStoreRelations->price = $vv['price'];
$DrugStoreRelations->buy_price = $vv['market_price'] ?? $vv['price'];
$DrugStoreRelations->status = $vv['status'];
$DrugStoreRelations->saveOrFail();
}
}
} catch (\Exception $e) {
$t->rollBack();
throw new Exception($e->getMessage());
}
$t->commit();
return ['同步成功'];
}
}