218 lines
6.8 KiB
PHP
218 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace admin\models\forms\drug;
|
|
|
|
use admin\controllers\StoreController;
|
|
use admin\models\Admin;
|
|
use common\core\BaseModel;
|
|
use common\enums\UserRoleEnum;
|
|
use common\models\CashAccount;
|
|
use common\models\Department;
|
|
use common\models\Hospital;
|
|
use common\models\Log;
|
|
use common\models\Store;
|
|
use common\services\WeappService;
|
|
use yii\db\Exception;
|
|
use yii\helpers\Json;
|
|
|
|
//科室form
|
|
class DepartForm extends BaseModel
|
|
{
|
|
public $hospital_id;
|
|
public $position;
|
|
|
|
public $depart_id;
|
|
public $yard_id;
|
|
public $name;
|
|
public $pid;
|
|
public $level;
|
|
public $feature;
|
|
public $logo;
|
|
|
|
public $image;
|
|
public $intro;
|
|
public $content;
|
|
|
|
|
|
public $id;
|
|
public $plate_id;
|
|
public $drugstore_id;
|
|
public $erp_id;
|
|
public $contact;
|
|
public $mobile;
|
|
public $offical_seal;
|
|
public $start_time;
|
|
public $end_time;
|
|
public $pic;
|
|
public $qr_code;
|
|
public $shouzimu;
|
|
public $store_name;
|
|
|
|
public $bank_user_name;
|
|
public $bank_card;
|
|
public $bank_name;
|
|
public $bank_account_type;
|
|
public $bank_no;
|
|
public $code;
|
|
public $province_id;
|
|
public $city_id;
|
|
|
|
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['name','level','offical_seal','code'],'required'],
|
|
[['position','logo','offical_seal','image','intro','content','contact','mobile','start_time','end_time','pic','qr_code','shouzimu','store_name','bank_user_name','bank_card','bank_name','bank_no'],'string'],
|
|
[['depart_id','hospital_id','pid','yard_id','plate_id','drugstore_id','id','bank_account_type','province_id','city_id','erp_id'],'integer'],
|
|
[['feature','pid'],'default','value'=>0],
|
|
];
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'erp_id'=>'对接的erp_id',
|
|
'code'=>'推广码',
|
|
'level'=>'级别',
|
|
'offical_seal'=>'公章',
|
|
'name'=>'名字',
|
|
'shouzimu'=>'首字母',
|
|
'start_time'=>'开始营业时间',
|
|
'end_time'=>'结束营业时间',
|
|
'qr_code'=>'门店二维码',
|
|
];
|
|
}
|
|
|
|
//新增科室
|
|
public function SaveDepart()
|
|
{
|
|
if (!$this->validate()){
|
|
throw new Exception($this->getErrorMsg());
|
|
}
|
|
$Department=Department::find()->where([
|
|
'name'=>$this->name
|
|
])->one();
|
|
if ($Department) throw new Exception('科室已存在');
|
|
if ($this->level != 1){
|
|
if (empty($this->pid)){
|
|
return ['pid不能为空'];
|
|
}
|
|
}
|
|
|
|
$department=new Department();
|
|
$department->attributes=$this->attributes;
|
|
$department->saveOrFail();
|
|
return ['添加成功'];
|
|
}
|
|
|
|
//新增门店
|
|
public function SaveStore()
|
|
{
|
|
$admin=Admin::find()->where(['code'=>$this->code,'role'=>UserRoleEnum::SUPPLY])->one();
|
|
if (!$admin)throw new Exception('推广码或业务员不存在');
|
|
|
|
if ($this->id){
|
|
$Store=Store::find()->where([
|
|
'plate_id'=>$this->plate_id,
|
|
'id'=>$this->id
|
|
])->one();
|
|
if (!$Store) throw new Exception('门店不存在');
|
|
|
|
if (!empty($this->bank_account_type)){
|
|
if ($this->bank_account_type== 1 || $this->bank_account_type == 5) {
|
|
if (empty($this->bank_no)) {
|
|
throw new Exception('bank_no不能为空');
|
|
}
|
|
} else {
|
|
if (substr($this->bank_card, 0, 2) != '62') {
|
|
if (empty($this->bank_no)) {
|
|
throw new Exception('bank_no不能为空');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$Store->plate_id=$this->plate_id;
|
|
$Store->drugstore_id=$this->drugstore_id;
|
|
$Store->name=$this->store_name;
|
|
if($this->erp_id){
|
|
$Store->erp_id=$this->erp_id;
|
|
}
|
|
$Store->shouzimu=$this->shouzimu;
|
|
$Store->contact=$this->contact;
|
|
$Store->offical_seal=$this->offical_seal??$Store->offical_seal;
|
|
$Store->province_id=$this->province_id;
|
|
$Store->city_id=$this->city_id;
|
|
$Store->position=$this->position;
|
|
$Store->mobile=$this->mobile;
|
|
$Store->uid=$admin->uid;
|
|
$Store->code=$this->code;
|
|
$Store->bank_user_name=$this->bank_user_name;
|
|
$Store->bank_card=$this->bank_card;
|
|
$Store->bank_name=$this->bank_name;
|
|
$Store->bank_account_type=$this->bank_account_type;
|
|
$Store->bank_no=$this->bank_no;
|
|
$Store->start_time=$this->start_time;
|
|
$Store->end_time=$this->end_time;
|
|
|
|
if(!$Store->qr_code){
|
|
$scene = 'STORE_QR_CODE'.'_'.$this->id;
|
|
$weappService = new WeappService();
|
|
$url= $weappService->getQrcode($scene);
|
|
$Store->qr_code = $url;
|
|
}
|
|
|
|
|
|
$Store->saveOrFail();
|
|
return ['编辑成功'];
|
|
}
|
|
$Store=Store::find()->where([
|
|
'plate_id'=>$this->plate_id,
|
|
'name'=>$this->name
|
|
])->one();
|
|
if ($Store) throw new Exception('门店已存在');
|
|
|
|
$t=\Yii::$app->db->beginTransaction();
|
|
try {
|
|
$Store=new Store();
|
|
$Store->plate_id=$this->plate_id;
|
|
$Store->drugstore_id=$this->drugstore_id;
|
|
$Store->erp_id=$this->erp_id;
|
|
$Store->name=$this->store_name;
|
|
$Store->contact=$this->contact;
|
|
$Store->offical_seal=$this->offical_seal??'';
|
|
$Store->province_id=$this->province_id;
|
|
$Store->city_id=$this->city_id;
|
|
$Store->position=$this->position;
|
|
$Store->mobile=$this->mobile;
|
|
$Store->uid=$admin->uid;
|
|
$Store->code=$this->code;
|
|
// $Store->bank_user_name=$this->bank_user_name;
|
|
// $Store->bank_card=$this->bank_card;
|
|
// $Store->bank_name=$this->bank_name;
|
|
// $Store->bank_account_type=$this->bank_account_type;
|
|
// $Store->bank_no=$this->bank_no;
|
|
$Store->start_time=$this->start_time;
|
|
$Store->end_time=$this->end_time;
|
|
$Store->shouzimu=$this->shouzimu;
|
|
$Store->saveOrFail();
|
|
|
|
$add_store = Store::find()->where([
|
|
'id' => $Store->id
|
|
])->one();
|
|
$scene = 'STORE_QR_CODE'.'_'.$add_store->id;
|
|
$weappService = new WeappService();
|
|
$url= $weappService->getQrcode($scene);
|
|
$add_store->qr_code=$url;
|
|
$add_store->saveOrFail();
|
|
// StoreController::actionQrcode($Store->id);
|
|
|
|
$t->commit();
|
|
return ['添加成功'];
|
|
}catch (\Exception $e){
|
|
$t->rollBack();
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
|
|
}
|
|
} |