产品服务包,分账
This commit is contained in:
@@ -3,16 +3,20 @@
|
||||
namespace admin\controllers\drug;
|
||||
|
||||
use admin\components\BaseAdminController;
|
||||
use admin\models\forms\drug\GranularForm;
|
||||
use admin\models\forms\drug\ImportForm;
|
||||
use admin\models\forms\drug\ServerForm;
|
||||
use common\enums\UserRoleEnum;
|
||||
use common\forms\LedgerForm;
|
||||
use common\helpers\FuncHelper;
|
||||
use common\models\newDb\AccountBalanceModel;
|
||||
use common\models\newDb\SupplierModel;
|
||||
use common\models\oldDb\CashAccount;
|
||||
use common\models\oldDb\Drug;
|
||||
use moonland\phpexcel\Excel;
|
||||
use common\models\oldDb\Ledger;
|
||||
use common\models\oldDb\LedgerLog;
|
||||
use common\models\oldDb\ProductOrder;
|
||||
use common\models\oldDb\ProductOrderItems;
|
||||
use common\models\oldDb\Store;
|
||||
use yii\db\Exception;
|
||||
use yii\web\UploadedFile;
|
||||
|
||||
/**
|
||||
* @doc-module 产品服务包库
|
||||
@@ -76,7 +80,7 @@ class ServerController extends BaseAdminController
|
||||
|
||||
$this->field = [
|
||||
Drug::class => [
|
||||
'id', 'pinyin_simple', 'drug_name', 'source', 'type', 'is_otc', 'category_first', 'category_second', 'small_info', 'info', 'content', 'usage', 'specification', 'image', 'status', 'drug_number', 'drug_alias', 'bar_code', 'guozi_no', 'place', 'function', 'instruction', 'decotion_id' => 'decotion', 'decotion' => 'drugUseWay.name', 'unit' => 'unit.name',
|
||||
'id', 'pinyin_simple', 'drug_name', 'source', 'type', 'is_otc', 'category_first', 'category_second', 'small_info', 'info', 'content', 'usage', 'image', 'status', 'drug_number', 'drug_alias', 'bar_code', 'guozi_no', 'place', 'function', 'instruction', 'decotion_id' => 'decotion', 'decotion' => 'drugUseWay.name', 'unit' => 'unit.name',
|
||||
'store' => 'drugStoreRelationes.store_id',
|
||||
'price' => 'drugStoreRelationes.price',
|
||||
'buy_price' => 'drugStoreRelationes.buy_price',
|
||||
@@ -88,6 +92,10 @@ class ServerController extends BaseAdminController
|
||||
'is_forbid'=>'drugStoreRelationes.is_forbid',
|
||||
'supplier',
|
||||
'source_name' => 'supplier.name',
|
||||
'specification',
|
||||
'platform_ledger',
|
||||
'store_ledger',
|
||||
'supplier_ledger',
|
||||
],
|
||||
];
|
||||
return $this->create($query, $get);
|
||||
@@ -131,7 +139,7 @@ class ServerController extends BaseAdminController
|
||||
$this->requestValidate($post,[
|
||||
['id','required']
|
||||
]);
|
||||
$GranularForm=new GranularForm();
|
||||
$GranularForm = new ServerForm();
|
||||
$GranularForm->attributes=$post;
|
||||
return $GranularForm->del();
|
||||
}
|
||||
@@ -153,7 +161,7 @@ class ServerController extends BaseAdminController
|
||||
$this->requestValidate($post,[
|
||||
['id','required']
|
||||
]);
|
||||
$GranularForm=new GranularForm();
|
||||
$GranularForm = new ServerForm();
|
||||
$GranularForm->attributes=$post;
|
||||
return $GranularForm->update();
|
||||
|
||||
@@ -173,35 +181,322 @@ class ServerController extends BaseAdminController
|
||||
return $drug;
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 导入产品服务包库
|
||||
* @doc-param file file 文件
|
||||
*/
|
||||
public function actionGranularImport()
|
||||
{
|
||||
$request = \Yii::$app->request;
|
||||
if ($request->isPost) {
|
||||
//设置最大执行时间
|
||||
ini_set("max_execution_time", "360");
|
||||
$file = UploadedFile::getInstanceByName('file');
|
||||
if ($file->size > 5 * 1024 * 1024) {
|
||||
return ['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',
|
||||
]);
|
||||
|
||||
$ImportForm=new ImportForm();
|
||||
return $ImportForm->GranularImport($data);
|
||||
} else {
|
||||
return ['请求方式错误'];
|
||||
}
|
||||
}
|
||||
# 后面可能回做一个结算重试
|
||||
// public function actionServiceLedger()
|
||||
// {
|
||||
// //门店可提现及累计金额更新
|
||||
// $supplierId = 1;
|
||||
//
|
||||
// $time = time();
|
||||
// /******************************************** 供应商 ********************************************** */
|
||||
// $storeTotal = Ledger::find()->where(['order_id' => -1, 'user_id' => $supplierId, 'user_type' => 3, 'order_type' => 1, 'fee_type' => 1])->sum('money'); // 该订单供应商分佣总金额
|
||||
// $storeTotal = round($storeTotal, 6)?? '20.01';//4舍5入
|
||||
// //增加供应商分佣
|
||||
// $log = new LedgerLog();
|
||||
// $log->order_id = -1;
|
||||
// $log->user_id = $supplierId;
|
||||
// $log->user_type = 3;// 供应商
|
||||
// $log->order_type = 1; //产品订单
|
||||
// $log->fee_type = 1; //药品费用
|
||||
// $log->type = 1;// 增加
|
||||
// $log->amount = $storeTotal;
|
||||
// $log->content = '订单结算后增加药品分佣金额';
|
||||
// $log->created_at = $time;
|
||||
// $log->updated_at = $time;
|
||||
// $log->saveOrFail();
|
||||
//
|
||||
//
|
||||
// //门店可提现及累计金额更新
|
||||
// AccountBalanceModel::updateAllCounters([
|
||||
// 'total' => $storeTotal,
|
||||
// 'frozen' => $storeTotal,
|
||||
// ], [
|
||||
// 'user_id' => $supplierId,
|
||||
// 'type' => 3
|
||||
// ]);
|
||||
// return ['分账成功'];
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// $t = \Yii::$app->db->beginTransaction();
|
||||
// $orderId = 314;
|
||||
// try {
|
||||
// $productOrder = ProductOrder::find()->with(['orderItems'])->where(['id' => $orderId])->one();
|
||||
// if (!$productOrder) {
|
||||
// throw new Exception('产品订单不存在');
|
||||
// }
|
||||
// $store = Store::findOne(['id' => $productOrder->store_id]);
|
||||
// if (!$store) {
|
||||
// throw new Exception('仓库不存在');
|
||||
// }
|
||||
// $isLegder = Ledger::find()->where(['order_id' => $orderId])->andWhere(['order_type' => 1])->one();
|
||||
// if (!empty($isLegder)) {
|
||||
// throw new Exception('该订单已增加待结算记录');
|
||||
// }
|
||||
// $time = time();
|
||||
// $ledgerData = [];
|
||||
// if ($productOrder->decoct_price > 0) {
|
||||
// $ledgerData[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => 0,
|
||||
// 'user_type' => 2, //平台
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 4,//代煎费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'drug_id' => 0,
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'number' => 1,
|
||||
// 'money' => $productOrder->decoct_price,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
// }
|
||||
// if ($productOrder->process_price > 0) {
|
||||
// $ledgerData[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => 0,
|
||||
// 'user_type' => 2, //供应商
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 5,//加工费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'drug_id' => 0,
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'number' => 1,
|
||||
// 'money' => $productOrder->process_price,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
// }
|
||||
// if ($productOrder->treatement_price > 0) {
|
||||
// $ledgerData[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => $store->id,
|
||||
// 'user_type' => 1, //门店
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 6,//诊疗费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'drug_id' => 0,
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'number' => 1,
|
||||
// 'money' => $productOrder->treatement_price,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
// }
|
||||
// if ($productOrder->trans_expenses > 0) {
|
||||
// $ledgerData[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => 0,
|
||||
// 'user_type' => 2, //平台
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 3,//快递费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'drug_id' => 0,
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'number' => 1,
|
||||
// 'money' => $productOrder->trans_expenses,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
// }
|
||||
// if (!empty($ledgerData)) {
|
||||
// \Yii::$app->db->createCommand()->batchInsert(Ledger::tableName(), [
|
||||
// 'order_id', 'user_id', 'user_type', 'order_type', 'fee_type', 'su_id', 'drugstore_id',
|
||||
// 'drug_id', 'xd_time', 'number', 'money', 'status', 'created_at', 'updated_at'
|
||||
// ], $ledgerData)->execute();
|
||||
// }
|
||||
// $productOrderItems = ProductOrderItems::find()->with(['drug.supplier'])->where(['product_order_id' => $productOrder->id])->asArray()->all();
|
||||
//
|
||||
// switch ($productOrder->prescription_type) {
|
||||
// case '1':
|
||||
// case '3': //中药/颗粒药分佣
|
||||
// foreach ($productOrderItems as $v) {
|
||||
// $ledger = [];
|
||||
// $number = $v['number'];
|
||||
// $totalPrice = round($number * $v['price'], 4);
|
||||
// $totalBuyPrice = round($number * $v['buy_price'], 4);
|
||||
//
|
||||
// $ledger[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => $store->id,
|
||||
// 'user_type' => 1, //门店
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 1,//药品费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'drug_id' => $v['drug_id'],
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'number' => $number,
|
||||
// 'money' => $totalPrice - $totalBuyPrice,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
//
|
||||
// $ledger[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => 0,
|
||||
// 'user_type' => 2, //平台
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 1,//药品费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'drug_id' => $v['drug_id'],
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'number' => $number,
|
||||
// 'money' => $totalBuyPrice,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
// \Yii::$app->db->createCommand()->batchInsert(Ledger::tableName(), [
|
||||
// 'order_id', 'user_id', 'user_type', 'order_type', 'fee_type', 'su_id', 'drugstore_id',
|
||||
// 'drug_id', 'xd_time', 'number', 'money', 'status', 'created_at', 'updated_at'
|
||||
// ], $ledger)->execute();
|
||||
// }
|
||||
// break;
|
||||
// case '2': //西药分佣
|
||||
// $ledger = [];
|
||||
// foreach ($productOrderItems as $v) {
|
||||
// $totalPrice = round($v['number'] * $v['price'], 4);
|
||||
// $totalBuyPrice = round($v['number'] * $v['buy_price'], 4);
|
||||
// $ledger[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => $store->id,
|
||||
// 'user_type' => 1, //门店
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 1,//药品费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'drug_id' => $v['drug_id'],
|
||||
// 'number' => $v['number'],
|
||||
// 'money' => $totalPrice - $totalBuyPrice,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
//
|
||||
// $ledger[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => 0,
|
||||
// 'user_type' => 2, //平台
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 1,//药品费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'drug_id' => $v['drug_id'],
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'number' => $v['number'],
|
||||
// 'money' => $totalBuyPrice,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
// \Yii::$app->db->createCommand()->batchInsert(Ledger::tableName(), [
|
||||
// 'order_id', 'user_id', 'user_type', 'order_type', 'fee_type', 'su_id', 'drugstore_id',
|
||||
// 'drug_id', 'xd_time', 'number', 'money', 'status', 'created_at', 'updated_at'
|
||||
// ], $ledger)->execute();
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
// case '5':
|
||||
// //产品服务包分成
|
||||
// $ledger = [];
|
||||
// foreach ($productOrderItems as $v) {
|
||||
// $totalPrice = bcmul($v['number'], $v['price'], 4);
|
||||
// $platformMoney = bcmul($totalPrice, $v['drug']['platform_ledger'] / 100, 4);
|
||||
// $storeMoney = bcmul($totalPrice, $v['drug']['store_ledger'] / 100, 4);
|
||||
// $supplierMoney = bcmul($totalPrice, $v['drug']['supplier_ledger'] / 100, 4);
|
||||
// $ledger[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => $store->id,
|
||||
// 'user_type' => 1, //门店
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 1,//药品费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'drug_id' => $v['drug_id'],
|
||||
// 'number' => $v['number'],
|
||||
// 'money' => $storeMoney,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
//
|
||||
// $ledger[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => 0,
|
||||
// 'user_type' => 2, //平台
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 1,//药品费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'drug_id' => $v['drug_id'],
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'number' => $v['number'],
|
||||
// 'money' => $platformMoney,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
//
|
||||
// $ledger[] = [
|
||||
// 'order_id' => $orderId,
|
||||
// 'user_id' => $v['drug']['supplier']['id'],
|
||||
// 'user_type' => 3, //平台
|
||||
// 'order_type' => 1,//产品订单
|
||||
// 'fee_type' => 1,//药品费用
|
||||
// 'su_id' => $productOrder->su_id,
|
||||
// 'drugstore_id' => $productOrder->store_id,
|
||||
// 'drug_id' => $v['drug_id'],
|
||||
// 'xd_time' => $productOrder->created_at,
|
||||
// 'number' => $v['number'],
|
||||
// 'money' => $supplierMoney,
|
||||
// 'status' => 0,
|
||||
// 'created_at' => $time,
|
||||
// 'updated_at' => $time
|
||||
// ];
|
||||
// ds($ledger);
|
||||
// \Yii::$app->db->createCommand()->batchInsert(Ledger::tableName(), [
|
||||
// 'order_id', 'user_id', 'user_type', 'order_type', 'fee_type', 'su_id', 'drugstore_id',
|
||||
// 'drug_id', 'xd_time', 'number', 'money', 'status', 'created_at', 'updated_at'
|
||||
// ], $ledger)->execute();
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// throw new Exception('错误的处方类型');
|
||||
// break;
|
||||
// }
|
||||
//// $t->commit();
|
||||
//
|
||||
//// $ledgerForm = new LedgerForm();
|
||||
//// $ledgerForm->order_id = $orderId;
|
||||
//// $ledgerForm->status = 1; // 已结算
|
||||
//// $ledgerForm->update();
|
||||
// } catch (\Exception $e) {
|
||||
// $t->rollBack();
|
||||
// throw $e;
|
||||
// }
|
||||
// return ['重试成功'];
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user