Commit caafce37 authored by clone's avatar clone

1

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