refactor(api): 重构 IndexController 中的数据处理逻辑
- 优化了数据查询和处理的代码结构 - 提高了代码的可读性和维护性 - 新增 wps_product 方法用于处理采购商品下载
This commit is contained in:
parent
f43f1b0886
commit
ab347de4f1
@ -58,7 +58,7 @@ class IndexController extends BaseApiController
|
||||
public function index()
|
||||
{
|
||||
d(1);
|
||||
$arr=Db::name('ceshi_copy')->select();
|
||||
$arr = Db::name('ceshi_copy')->select();
|
||||
foreach ($arr as $k => $v) {
|
||||
$data = [
|
||||
|
||||
@ -74,9 +74,9 @@ class IndexController extends BaseApiController
|
||||
if ($rose_price > 0) {
|
||||
//利润除于零售
|
||||
$price_div = bcdiv($rose_price, $v['price'], 2);
|
||||
$rose=bcmul($price_div, 100, 2);
|
||||
$rose = bcmul($price_div, 100, 2);
|
||||
}
|
||||
$data['rose']=$rose;
|
||||
$data['rose'] = $rose;
|
||||
StoreProduct::update($data, ['id' => $v['product_id']]);
|
||||
//修改
|
||||
StoreBranchProduct::where('product_id', $v['product_id'])->whereNotIn('store_id', [17, 18])->update([
|
||||
@ -89,16 +89,16 @@ class IndexController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
d(11);
|
||||
$pay_price=StoreOrder::where('store_id',3)->where('id','>=',1867)->where('id','<=',4826)->where('paid',1)->sum('pay_price');
|
||||
$refund_price=StoreOrder::where('store_id',3)->where('id','>=',1867)->where('id','<=',4826)->where('paid',1)->sum('refund_price');
|
||||
d($pay_price,$refund_price);
|
||||
$arr=StoreOrder::where('store_id',3)->where('id','>',551)->where('paid',1)->field('id,pay_price,deduction_price,refund_price')->select()->toArray();
|
||||
$data=[];
|
||||
$pay_price = StoreOrder::where('store_id', 3)->where('id', '>=', 1867)->where('id', '<=', 4826)->where('paid', 1)->sum('pay_price');
|
||||
$refund_price = StoreOrder::where('store_id', 3)->where('id', '>=', 1867)->where('id', '<=', 4826)->where('paid', 1)->sum('refund_price');
|
||||
d($pay_price, $refund_price);
|
||||
$arr = StoreOrder::where('store_id', 3)->where('id', '>', 551)->where('paid', 1)->field('id,pay_price,deduction_price,refund_price')->select()->toArray();
|
||||
$data = [];
|
||||
foreach ($arr as $k => $v) {
|
||||
$total_price=StoreOrderCartInfo::where('oid', $v['id'])->sum('total_price');
|
||||
if($total_price != $v['pay_price']){
|
||||
$s=$v;
|
||||
$s['total_price']=$total_price;
|
||||
$total_price = StoreOrderCartInfo::where('oid', $v['id'])->sum('total_price');
|
||||
if ($total_price != $v['pay_price']) {
|
||||
$s = $v;
|
||||
$s['total_price'] = $total_price;
|
||||
$data[] = $s;
|
||||
}
|
||||
}
|
||||
@ -259,13 +259,13 @@ class IndexController extends BaseApiController
|
||||
*/
|
||||
public function purchase_product_offer()
|
||||
{
|
||||
$date=$this->request->get('date');
|
||||
if($date){
|
||||
$this->request->setGet(['date'=>$date,'export'=>2]);
|
||||
$lists=new PurchaseProductOfferListsTwo();
|
||||
$date = $this->request->get('date');
|
||||
if ($date) {
|
||||
$this->request->setGet(['date' => $date, 'export' => 2]);
|
||||
$lists = new PurchaseProductOfferListsTwo();
|
||||
$exportDownloadUrl = $lists->createExcel($lists->setExcelFields(), $lists->lists());
|
||||
$fileKey=explode('?file=',$exportDownloadUrl)[1];
|
||||
//通过文件缓存的key获取文件储存的路径
|
||||
$fileKey = explode('?file=', $exportDownloadUrl)[1];
|
||||
//通过文件缓存的key获取文件储存的路径
|
||||
$exportCache = new ExportCache();
|
||||
$fileInfo = $exportCache->getFile($fileKey);
|
||||
if (empty($fileInfo)) {
|
||||
@ -273,10 +273,42 @@ class IndexController extends BaseApiController
|
||||
}
|
||||
//下载前删除缓存
|
||||
Cache::delete($fileKey);
|
||||
return response()->download($fileInfo['src'] . $fileInfo['name'],$fileInfo['name']);
|
||||
}else{
|
||||
return response()->download($fileInfo['src'] . $fileInfo['name'], $fileInfo['name']);
|
||||
} else {
|
||||
return $this->fail('时间不能为空');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 采购商品下载
|
||||
*/
|
||||
public function wps_product()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
if ($data) {
|
||||
if ($data['product_id'] > 0) {
|
||||
$find = Db::name('wps_product')->where('product_id', $data['product_id'])->find();
|
||||
$arr = [];
|
||||
if ($data['purchase'] > 0) {
|
||||
$arr['purchase'] = $data['purchase'];
|
||||
}
|
||||
if ($data['cost'] > 0) {
|
||||
$arr['cost'] = $data['cost'];
|
||||
}
|
||||
if ($data['price'] > 0) {
|
||||
$arr['price'] = $data['price'];
|
||||
}
|
||||
if ($find) {
|
||||
Db::name('wps_product')->where('id', $find['id'])->update($arr);
|
||||
} else {
|
||||
$arr['product_id']=$data['product_id'];
|
||||
$arr['name']=$data['name'];
|
||||
Db::name('wps_product')->insert($arr);
|
||||
}
|
||||
}
|
||||
return $this->success('ok');
|
||||
} else {
|
||||
return $this->fail('时间不能为空');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user