Commit caafce37 authored by clone's avatar clone

1

parent 80d6a149
...@@ -154,7 +154,6 @@ class StoreFeeService ...@@ -154,7 +154,6 @@ class StoreFeeService
private function applyForFeeBin($id, $type, $fee_item, $total_fee, $agent_id, $store_id, $purpose, $site_id, $card_name, private function applyForFeeBin($id, $type, $fee_item, $total_fee, $agent_id, $store_id, $purpose, $site_id, $card_name,
$bank, $card_no, $count_time, $office_id, $status, $source = 0) $bank, $card_no, $count_time, $office_id, $status, $source = 0)
{ {
$arr = []; $arr = [];
if ($type) { if ($type) {
$arr["type"] = $type; $arr["type"] = $type;
...@@ -711,42 +710,54 @@ class StoreFeeService ...@@ -711,42 +710,54 @@ class StoreFeeService
public function importStoreFee($file_path) public function importStoreFee($file_path)
{ {
echo 111;
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(true); $reader->setReadDataOnly(true);
$spreadsheet = ""; $spreadsheet = "";
try { try {
$spreadsheet = $reader->load("static/excel/" . $file_path); $spreadsheet = $reader->load("static/excel/" . $file_path);
} catch (\Exception $exception) { } catch (\Exception $exception) {
return "找不到文件路径"; return ["code"=>101,"msg"=> "找不到文件路径"];
} }
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$highestRow = $sheet->getHighestRow(); // 最大行数 $highestRow = $sheet->getHighestRow(); // 最大行数
$highestColumn = $sheet->getHighestColumn(); // 最大列数 if ($highestRow <= 2) {
$highestColumn = "AB"; return ["code"=>101,"msg"=> "Excel没有任何数据"];
// 把下标变成数字,如A-Z分别对应1-26,AA对应27,AB对应28,以此类推 }
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn); $data = array();
/* if($highestRow <= 2){ // 因为students.xlsx表格数据是从第三行开始的 $storeModel = new AStore();
exit('Excel没有任何数据'); for ($row = 3; $row <= $highestRow; $row++) {
}*/ $count_time = $sheet->getCellByColumnAndRow(1, $row)->getValue();
$data = array(); $toTimestamp = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($count_time);
for ($row = 0; $row <= $highestRow; $row++) { $date = date("Y-m-01", $toTimestamp);
$type = $sheet->getCellByColumnAndRow(1, $row)->getValue(); $total_fee = $sheet->getCellByColumnAndRow(2, $row)->getValue();
$fee_item = $sheet->getCellByColumnAndRow(2, $row)->getValue(); $type = $sheet->getCellByColumnAndRow(3, $row)->getValue();
$total_fee = $sheet->getCellByColumnAndRow(3, $row)->getValue(); $fee_item = $sheet->getCellByColumnAndRow(4, $row)->getValue();
$agent_id = $sheet->getCellByColumnAndRow(4, $row)->getValue(); $purpose = $sheet->getCellByColumnAndRow(5, $row)->getValue();
$store_id = $sheet->getCellByColumnAndRow(5, $row)->getValue(); $store_id = $sheet->getCellByColumnAndRow(6, $row)->getValue();
$purpose = $sheet->getCellByColumnAndRow(6, $row)->getValue();
$site_id = $sheet->getCellByColumnAndRow(7, $row)->getValue(); $if_verify = $this->verifyType((int)$type, (int)$fee_item);
$card_name = $sheet->getCellByColumnAndRow(8, $row)->getValue(); if (!$if_verify) {
$bank = $sheet->getCellByColumnAndRow(9, $row)->getValue(); return ["code"=>101,"msg"=> "类型选择错误"];
$card_no = $sheet->getCellByColumnAndRow(10, $row)->getValue(); }
$count_time = $sheet->getCellByColumnAndRow(11, $row)->getValue();
$office_id = $sheet->getCellByColumnAndRow(12, $row)->getValue(); $storeInfo = $storeModel->getStoreById($store_id);
array_push($data, $this->applyForFeeBin($type, $fee_item, $total_fee, $agent_id, $store_id, $purpose, $site_id, $card_name, if (!$storeInfo || !$storeInfo["agents_id"] || !$storeInfo["site_id"]) {
$bank, $card_no, $count_time, $office_id, 0, 1, 1)); return ["code"=>101,"msg"=> "门店信息错误"];
} }
dump($data); $agent_id = $storeInfo["agents_id"];
$site_id = $storeInfo["site_id"];
$office_id = $storeInfo["office_id"];
array_push($data, $this->applyForFeeBin(0, $type, $fee_item, $total_fee, $agent_id, $store_id, $purpose, $site_id, "",
"", "", $date, $office_id, 0, 1));
}
if($data){
$applyForModel = new FApplyForFee();
$is_ok = $applyForModel->addData($data);
return ["code"=>200,"msg"=> "$is_ok"];
}
return ["code"=>101,"msg"=> "未知异常"];
} }
......
...@@ -43,10 +43,10 @@ class StoreFee extends Basic ...@@ -43,10 +43,10 @@ class StoreFee extends Basic
public function creationStoreFee() public function creationStoreFee()
{ {
$params = $this->params; $params = $this->params;
/* $params = array( /* $params = array(
"setting_date" => "2019-06-01", "setting_date" => "2019-06-01",
"agent_id" => 1, "agent_id" => 1,
);*/ );*/
if (!$params["setting_date"] || !$params["agent_id"]) { if (!$params["setting_date"] || !$params["agent_id"]) {
return $this->response("101", "请求参数错误 "); return $this->response("101", "请求参数错误 ");
} }
...@@ -56,21 +56,21 @@ class StoreFee extends Basic ...@@ -56,21 +56,21 @@ class StoreFee extends Basic
// 验证用户数据 // 验证用户数据
$cache = new RedisCacheService(); $cache = new RedisCacheService();
$agent_info = $cache->getRedisCache(2, $agent_id); $agent_info = $cache->getRedisCache(2, $agent_id);
if(!$agent_info){ if (!$agent_info) {
return $this->response("101", "用户不存在 "); return $this->response("101", "用户不存在 ");
} }
$agent_name = $agent_info["name"]; $agent_name = $agent_info["name"];
// 1.判断是否都审核过, // 1.判断是否都审核过,
$is_check = $this->service_->verifyCheck($setting_date); $is_check = $this->service_->verifyCheck($setting_date);
if(!$is_check){ if (!$is_check) {
return $this->response("101", "请先审核所有设置数据然后再提交一键生成! "); return $this->response("101", "请先审核所有设置数据然后再提交一键生成! ");
} }
// 2.计算门店成本 3.总部成本,4.分部成本,5.同联发展基金 6门店单独成本 // 2.计算门店成本 3.总部成本,4.分部成本,5.同联发展基金 6门店单独成本
$msg = $this->service_->calculateStoreFee($setting_date, $agent_id,$agent_name); $msg = $this->service_->calculateStoreFee($setting_date, $agent_id, $agent_name);
if($msg != 1){ if ($msg != 1) {
return $this->response("101", $msg); return $this->response("101", $msg);
}else{ } else {
return $this->response("200", "success"); return $this->response("200", "success");
} }
} }
...@@ -78,7 +78,8 @@ class StoreFee extends Basic ...@@ -78,7 +78,8 @@ class StoreFee extends Basic
/** /**
* @return \think\Response * @return \think\Response
*/ */
public function getCost(){ public function getCost()
{
$params = $this->params; $params = $this->params;
/* $params = array( /* $params = array(
"setting_date" => "2019-06-01", "setting_date" => "2019-06-01",
...@@ -87,11 +88,11 @@ class StoreFee extends Basic ...@@ -87,11 +88,11 @@ class StoreFee extends Basic
return $this->response("101", "请求参数错误 "); return $this->response("101", "请求参数错误 ");
} }
$setting_date = $params["setting_date"]; $setting_date = $params["setting_date"];
$result = $this->service_->getCost($setting_date); $result = $this->service_->getCost($setting_date);
if($result){ if ($result) {
return $this->response("200","当月已提交过一键生成,是否重新提交覆盖原来的数据?"); return $this->response("200", "当月已提交过一键生成,是否重新提交覆盖原来的数据?");
}else{ } else {
return $this->response("101","暂未生成 $setting_date 数据"); return $this->response("101", "暂未生成 $setting_date 数据");
} }
} }
...@@ -101,41 +102,46 @@ class StoreFee extends Basic ...@@ -101,41 +102,46 @@ class StoreFee extends Basic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getStoreFeeDetail(){ public function getStoreFeeDetail()
{
$params = $this->params; $params = $this->params;
/* $params = array( /* $params = array(
"setting_date" => "2019-06-01", "setting_date" => "2019-06-01",
"store_id" => 49, "store_id" => 49,
);*/ );*/
if (!$params["setting_date"] || !$params["store_id"]) { if (!$params["setting_date"] || !$params["store_id"]) {
return $this->response("101", "请求参数错误 "); return $this->response("101", "请求参数错误 ");
} }
$setting_date = $params["setting_date"]; $setting_date = $params["setting_date"];
$store_id = $params["store_id"]; $store_id = $params["store_id"];
$result = $this->service_->getStoreFeeDetail($setting_date,$store_id); $result = $this->service_->getStoreFeeDetail($setting_date, $store_id);
if($result){ if ($result) {
return $this->response("200","success",$result); return $this->response("200", "success", $result);
}else{ } else {
return $this->response("101","暂未生成 $setting_date 数据"); return $this->response("101", "暂未生成 $setting_date 数据");
} }
} }
public function importStoreFee() public function importStoreFee()
{ {
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
/* set_time_limit(0); set_time_limit(0);
$file = $_FILES['file']; $file = $_FILES['file'];
$type = request()->param('type'); //excel_import $type = request()->param('type'); //excel_import
$uploadFileService = new UploadFileService(); $uploadFileService = new UploadFileService();
$uploadResult = $uploadFileService->upload($file, $type, 15000000, ['xls', 'xlsx']); $uploadResult = $uploadFileService->upload($file, $type, 15000000, ['xls', 'xlsx']);
if ($uploadResult["code"] == 200) {*/ if ($uploadResult["code"] == 200) {
// $result = $this->service_->importStoreFee($uploadResult["msg"]); $result = $this->service_->importStoreFee($uploadResult["msg"]["img_path"]);
$result = $this->service_->importStoreFee("20190820/20190820110629513.xlsx"); if ($result["code"] == 200) {
/* return $this->response("200", "excel上传成功", $uploadResult["msg"]); return $this->response("200", "excel导入成功");
} else {
return $this->response("101", $result["msg"]);
}
} else { } else {
return $this->response("101", $uploadResult["msg"]); return $this->response("101", $uploadResult["msg"]);
}*/ }
} }
/** /**
...@@ -454,7 +460,7 @@ class StoreFee extends Basic ...@@ -454,7 +460,7 @@ class StoreFee extends Basic
$id = $status = 0; $id = $status = 0;
if ($check_url == 'index/addApplyFor') { if ($check_url == 'index/addApplyFor') {
$checkResult = $validate->scene("pcAddApplyFor")->check($params); $checkResult = $validate->scene("pcAddApplyFor")->check($params);
$status = 1; $status = 1;
} else { } else {
$id = $params['id']; $id = $params['id'];
$checkResult = $validate->scene("pcEditApplyFor")->check($params); $checkResult = $validate->scene("pcEditApplyFor")->check($params);
...@@ -479,12 +485,12 @@ class StoreFee extends Basic ...@@ -479,12 +485,12 @@ class StoreFee extends Basic
if (!$img_arr && $check_url == 'index/addApplyFor') { if (!$img_arr && $check_url == 'index/addApplyFor') {
return $this->response("101", "请上传图片"); return $this->response("101", "请上传图片");
} }
$service_ = new StoreFeeService(); $service_ = new StoreFeeService();
//不验证 1办公室成本 2总部成本 //不验证 1办公室成本 2总部成本
if ($params['fee_item'] == 3 || $params['fee_item'] == 4) { if ($params['fee_item'] == 3 || $params['fee_item'] == 4) {
$if_verify = $service_->verifyType($type, $fee_item); $if_verify = $service_->verifyType($type, $fee_item);
if(!$if_verify){ if (!$if_verify) {
return $this->response("101", "类型选择错误"); return $this->response("101", "类型选择错误");
} }
} }
...@@ -539,7 +545,7 @@ class StoreFee extends Basic ...@@ -539,7 +545,7 @@ class StoreFee extends Basic
} }
$service_ = new StoreFeeService(); $service_ = new StoreFeeService();
$result = $service_->delImg($this->params['id_string']); $result = $service_->delImg($this->params['id_string']);
if ($result['status'] != 'fail') { if ($result['status'] != 'fail') {
$code = 200; $code = 200;
...@@ -558,7 +564,7 @@ class StoreFee extends Basic ...@@ -558,7 +564,7 @@ class StoreFee extends Basic
*/ */
public function addFeeImage() public function addFeeImage()
{ {
$code = 101; $code = 101;
$img_arr = json_decode($this->params["img_arr"], true); $img_arr = json_decode($this->params["img_arr"], true);
if (!is_array($img_arr)) { if (!is_array($img_arr)) {
...@@ -566,10 +572,10 @@ class StoreFee extends Basic ...@@ -566,10 +572,10 @@ class StoreFee extends Basic
} }
$service_ = new StoreFeeService(); $service_ = new StoreFeeService();
$num = $service_->saveImageData($img_arr, $this->params['id']); $num = $service_->saveImageData($img_arr, $this->params['id']);
if ($num > 0) { if ($num > 0) {
$code = 200; $code = 200;
$msg = '上传成功'; $msg = '上传成功';
} else { } else {
$msg = '上传失败'; $msg = '上传失败';
} }
......
...@@ -118,7 +118,7 @@ class AStore extends BaseModel ...@@ -118,7 +118,7 @@ class AStore extends BaseModel
public function getStoreById($id) { public function getStoreById($id) {
$data = $this->where('id',$id)->where('status',0)->find(); $data = $this->where('id',$id)->where('status',0)->find();
$agents = new AAgents(); $agents = new AAgents();
$agents_name = $agents->field('id,name,phone')->where('store_id',$data['id'])->where('level','in',[20,40])->find(); $agents_name = $agents->field('id,name,phone,site_id')->where('store_id',$data['id'])->where('level','in',[20,40])->find();
$data['district_name'] = Db::table('a_district')->where('id',$data['district_id'])->value('district_name'); $data['district_name'] = Db::table('a_district')->where('id',$data['district_id'])->value('district_name');
$data['agents_id'] = $agents_name['id']; $data['agents_id'] = $agents_name['id'];
$data['agents_name'] = $agents_name['name'].'-'.$agents_name['phone']; $data['agents_name'] = $agents_name['name'].'-'.$agents_name['phone'];
......
...@@ -27,6 +27,22 @@ class FApplyForFee extends BaseModel ...@@ -27,6 +27,22 @@ class FApplyForFee extends BaseModel
$id = $this->db_->insertGetId($data); $id = $this->db_->insertGetId($data);
return $id; return $id;
} }
/**
* @param $params
* @return int
*/
public function addData($params)
{
Db::startTrans();
try {
$this->db_->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/** /**
* @param $data * @param $data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment