一、open_basedir 不能再写 /tmp(7.4 池子把白名单收紧,Monolog/EasyWeChat 会抛异常)
- addons/shopro/library/Wechat.php:easywechat 日志改到 runtime/easywechat/
- addons/epay/library/Yansongda/Supports/Logger.php:epay 日志默认路径改到 runtime/epay/
- application/admin/library/traits/Backend.php:CSV 导入临时文件改到 runtime/temp/
二、implode 参数反序(7.4 起 E_DEPRECATED,TP5 会抛异常)
- application/api/controller/Datas.php
- application/index/controller/wms/Pda.php
- 另修正 Wms.php 中 1 处(拆分面单提示)
三、null 取下标(7.4 起 "Trying to access array offset on value of type null")
- 覆盖 71 个文件 135 行:find()/value()/json_decode()/redis get 等结果未判空即取下标处,
统一 (\['k'] ?? null) 兜底;foreach 目标用 ?? [];in_array/count 等数组参数用 ?? []
- 涉及 api/*、admin/shopro/*、addons/shopro/*、addons/epay/*、index/wms/* 等
四、嵌套三元未加括号(7.4 弃用)
- application/index/controller/wms/Wms.php getPackingprice 2 处,补括号后与旧版本解析顺序一致
验证:74 个文件、148 行改动,逐行括号/引号配平与 HEAD 一致,未改动 vendor/ 与 thinkphp/;
剩余扫描命中均为写目标、unset、或已被 if(!\){error()} 拦截的假阳性。
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1280 lines
54 KiB
PHP
1280 lines
54 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use app\common\controller\Api;
|
||
|
||
|
||
use fast\Random;
|
||
use think\Db;
|
||
use think\db\exception\BindParamException;
|
||
use think\db\exception\DataNotFoundException;
|
||
use think\db\exception\ModelNotFoundException;
|
||
use think\exception\DbException;
|
||
use think\exception\PDOException;
|
||
use think\exception\ValidateException;
|
||
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||
use fast\Http;
|
||
use GuzzleHttp\Client;
|
||
use GuzzleHttp\Exception\RequestException;
|
||
use GuzzleHttp\Psr7\Request;
|
||
use GuzzleHttp\Psr7\MultipartStream as MultipartStream;
|
||
use app\index\library\Wsdl;
|
||
/**
|
||
* 示例接口
|
||
*/
|
||
class Statements extends Api
|
||
{
|
||
|
||
//如果$noNeedLogin为空表示所有接口都需要登录才能请求
|
||
//如果$noNeedRight为空表示所有接口都需要验证权限才能请求
|
||
//如果接口已经设置无需登录,那也就无需鉴权了
|
||
//
|
||
// 无需登录的接口,*表示全部
|
||
protected $noNeedLogin = ['test', 'test1'];
|
||
// 无需鉴权的接口,*表示全部
|
||
protected $noNeedRight = ['test2','downloadFile','export_bill_task','export_task_bill','downloadBill','supplier_list_all','supplier_item_import','receivable_import','export_supplier_excel'];
|
||
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->DailyaccountModel = new \app\common\model\datas\Dailyaccount;
|
||
$this->AccounttypeModel = new \app\common\model\Accounttype;
|
||
$this->AccountModel = new \app\common\model\bank\Account;
|
||
$this->UserModel = new \app\common\model\User;
|
||
$this->HisorderModel = new \app\common\model\Hisorder;
|
||
|
||
}
|
||
/**
|
||
* 测试方法
|
||
*
|
||
* @ApiTitle (测试名称)
|
||
* @ApiSummary (测试描述信息)
|
||
* @ApiMethod (POST)
|
||
* @ApiRoute (/api/demo/test/id/{id}/name/{name})
|
||
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
||
* @ApiParams (name="id", type="integer", required=true, description="会员ID")
|
||
* @ApiParams (name="name", type="string", required=true, description="用户名")
|
||
* @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
|
||
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
||
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
||
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
|
||
* @ApiReturn ({
|
||
'code':'1',
|
||
'msg':'返回成功'
|
||
})
|
||
*/
|
||
public function configs()
|
||
{
|
||
|
||
$Paracodemodel = new \app\common\model\wms\Paracode;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$types = $this->AccounttypeModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isin"=>0,"isDelete"=>0])->select();
|
||
$types2 = $this->AccounttypeModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isin"=>1,"isDelete"=>0])->select();
|
||
$bank_account = $this->AccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"canUse"=>1,"isDelete"=>0])->select();
|
||
$bank_account2 = $this->AccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"canUse"=>0,"isDelete"=>0])->select();
|
||
$data2=$Paracodemodel->field("CODE,NAME")->where(["TYPE"=>"301"])->select();
|
||
$this->success('返回成功', [$types,$bank_account,$bank_account2,$types2,$data2]);
|
||
}
|
||
public function lists(){
|
||
|
||
$Paracodemodel = new \app\common\model\wms\Paracode;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$types = $this->AccounttypeModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$bank_account2 = $this->AccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"canUse"=>1])->select();
|
||
$params=$this->request->post();
|
||
$userid = $this->auth->id;
|
||
$page = $params["page"];
|
||
$storeid = $params["storeid"];
|
||
$pagesize = 20;
|
||
$list = $this->DailyaccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0])->where("createTime","BETWEEN",[strtotime($params["selectTime"][0]),strtotime($params["selectTime"][1])+86399]);
|
||
if($storeid>-1){
|
||
$list->where(["STOREID"=>$storeid]);
|
||
}
|
||
$list->where(["issettlement"=>2,"userid"=>$userid]);
|
||
$count2 = $list->count();
|
||
|
||
$list = $this->DailyaccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0])->where("createTime","BETWEEN",[strtotime($params["selectTime"][0]),strtotime($params["selectTime"][1])+86399]);
|
||
if($storeid>-1){
|
||
$list->where(["STOREID"=>$storeid]);
|
||
}
|
||
$list->where(["issettlement"=>0]);
|
||
$count3 = $list->count();
|
||
|
||
$list = $this->DailyaccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0])->where("createTime","BETWEEN",[strtotime($params["selectTime"][0]),strtotime($params["selectTime"][1])+86399]);
|
||
if($storeid>-1){
|
||
$list->where(["STOREID"=>$storeid]);
|
||
}
|
||
if($params["is_examine"]!=-1){
|
||
$list->where(["issettlement"=>$params["is_examine"]]);
|
||
if($params["is_examine"]==2){
|
||
$list->where(["userid"=>$userid]);
|
||
}
|
||
}
|
||
switch($params['all_type']){
|
||
case -1:
|
||
break;
|
||
case 0:
|
||
$types_array = [];
|
||
foreach ($types as $r){
|
||
if($r["isin"]==0){
|
||
array_push($types_array,$r["id"]);
|
||
}
|
||
}
|
||
$list->where("type","in",$types_array);
|
||
break;
|
||
case 1:
|
||
$types_array = [];
|
||
foreach ($types as $r){
|
||
if($r["isin"]==1){
|
||
array_push($types_array,$r["id"]);
|
||
}
|
||
}
|
||
$list->where("type","in",$types_array);
|
||
break;
|
||
default:
|
||
|
||
}
|
||
$offset = $pagesize*($page-1);
|
||
$lists = $list->order('id','desc')->paginate($pagesize);
|
||
$list = $lists->items();
|
||
$count = $lists->total();
|
||
$list = json_decode(json_encode($list),true);
|
||
$user = [];
|
||
foreach ($list as $item){
|
||
if($item["userid"]>0){
|
||
array_push($user,$item["userid"]);
|
||
}
|
||
if($item["settlement_userid"]>0){
|
||
array_push($user,$item["settlement_userid"]);
|
||
}
|
||
}
|
||
$users = $this->UserModel->where("id","in",$user)->select();
|
||
|
||
$data2=$Paracodemodel->field("CODE,NAME")->where(["TYPE"=>"301"])->select();
|
||
|
||
foreach ($list as $k => $item){
|
||
$list[$k]["credential"] = array_filter(explode(",",$item["credential"]));
|
||
$list[$k]["canedit"] = 0;
|
||
if($item["userid"]==$userid && $item["issettlement"]==0){
|
||
$list[$k]["canedit"] = 1;
|
||
}
|
||
foreach ($data2 as $post){
|
||
if($post["CODE"]==$item["Express"]){
|
||
$list[$k]['express'] = $post;
|
||
}
|
||
}
|
||
foreach ($types as $type){
|
||
if($item["type"]==$type["id"]){
|
||
$list[$k]['type'] = $type;
|
||
}
|
||
}
|
||
$list[$k]['bank_name'] = "";
|
||
foreach($bank_account2 as $bank){
|
||
if($item["bank_id"]==$bank["id"]){
|
||
$list[$k]['bank_name'] = $bank["name"];
|
||
}
|
||
}
|
||
foreach ($users as $user){
|
||
if($item["userid"]==$user["id"]){
|
||
$list[$k]["user_name"] = $user["real_name"];
|
||
}
|
||
if($item["settlement_userid"]==$user["id"]){
|
||
$list[$k]["settlement_username"] = $user["real_name"];
|
||
}
|
||
}
|
||
}
|
||
$hasrepeateRule = $this->auth->check("statements/hasrepeate");
|
||
$this->success('返回成功', ["list"=>$list,"count"=>$count,"count2"=>$count2,"count3"=>$count3,"page"=>$page,"hasrepeateRule"=>$hasrepeateRule]);
|
||
}
|
||
public function hasrepeate(){
|
||
$params=$this->request->post();
|
||
$id = $params["id"];
|
||
$userid = $this->auth->id;
|
||
Db::startTrans();
|
||
try {
|
||
//是否采用模型验证
|
||
$line = $this->DailyaccountModel->where(["id"=>$id,"issettlement"=>1])->find();
|
||
if(!$line){
|
||
$this->error("记录不存在或已处理");
|
||
}else{
|
||
if($line["supplier_bills"]){
|
||
$supplier_ids = explode(",",$line["supplier_bills"]);
|
||
$BillModel = new \app\common\model\supplier\Bill;
|
||
$list = $BillModel->where(["lists.WAREHOUSEID"=>$WAREHOUSEID])->where("bill.id","in",$supplier_bills)->with(['lists'])->select();
|
||
foreach ($list as $r){
|
||
$r->isPay = 2;
|
||
$r->save();
|
||
}
|
||
}
|
||
$bank = $this->AccountModel->where(["id"=>$line["bank_id"]])->lock(true)->find();
|
||
$account = ($bank["account"] ?? null);
|
||
$type = $this->AccounttypeModel->where(["id"=>$line["type"]])->find();
|
||
switch (($type["isin"] ?? null)) {
|
||
case 0:
|
||
$account +=$line["account"];
|
||
break;
|
||
case 1:
|
||
$account -=$line["account"];
|
||
break;
|
||
}
|
||
$bank->save(["account"=>$account]);
|
||
$res = $line->save(["issettlement"=>2,"settlement_userid"=>$userid,"examineTime"=>time()]);
|
||
}
|
||
Db::commit();
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
if ($res === false) {
|
||
$this->error(__('No rows were inserted'));
|
||
}
|
||
$this->success("反审成功",$res);
|
||
}
|
||
public function save(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$params=$this->request->post();
|
||
$form = $params["form"];
|
||
$editid = $params['editid'];
|
||
$userid = $this->auth->id;
|
||
if(!isset($form["date"])||$form["date"]==""){
|
||
$this->error("发生时间未选择");
|
||
}
|
||
$type = $this->AccounttypeModel->where(["id"=>$form["type"],"isDelete"=>0])->find();
|
||
if(!$type){
|
||
$this->error("记账科目不存在");
|
||
}
|
||
if($form["count"]==0 && $type["isExpress"]==1){
|
||
$this->error("快递充值数量不能为0");
|
||
}
|
||
if($form["storeid"]==0 && $type["isExpress"]==1){
|
||
$this->error("快递充值需要选择货主");
|
||
}
|
||
if($form["isInit"]==1){
|
||
if($type["isInit"]!=1){
|
||
$this->error("记账科目错误");
|
||
}
|
||
$bank = $this->AccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"canUse"=>0,"isDelete"=>0,"id"=>$form["bank_id"]])->find();
|
||
if(!$bank){
|
||
$this->error("账户不存在或已初始化");
|
||
}
|
||
$form["count"] = 0;
|
||
$form["price"] = 0;
|
||
$form["storeid"] = 0;
|
||
}else{
|
||
if(isset($form["account"])&&$form["account"]==0){
|
||
$this->error("金额不能为0");
|
||
}
|
||
$bank = $this->AccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"canUse"=>1,"isDelete"=>0,"id"=>$form["bank_id"]])->find();
|
||
if(!$bank){
|
||
$this->error("账户不存在或未初始化");
|
||
}
|
||
}
|
||
if($form["account"]>0 && $form["count"]>0 && $form["price"]>0 && $form["account"]!=strval(($form["count"]*100*$form["price"])/100)){
|
||
|
||
$this->error("单价X数量不等于总价");
|
||
}
|
||
$insertData = [
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"type"=>$form["type"],
|
||
"createTime"=>time(),
|
||
"occurrenceTime"=>strtotime($form["date"]),
|
||
"payTime"=>strtotime($form["paydate"]),
|
||
"credential"=>implode(",",$form["credential"]),
|
||
"remarks"=>$form["remarks"],
|
||
"userid"=>$userid,
|
||
"isDelete"=>0,
|
||
"account"=>$form["account"],
|
||
"STOREID"=>$form["storeid"],
|
||
"count"=>$form["count"],
|
||
"price"=>$form["price"],
|
||
"issettlement"=>0,
|
||
"settlement_userid"=>0,
|
||
"bank_id"=>$form["bank_id"],
|
||
"isRecharge"=>$form["isExpress"]?$form["isRecharge"]:0,
|
||
"Recharged"=>0,
|
||
"Express"=>$form["ExpressCode"]
|
||
];
|
||
$supplier_bills = isset($form["supplier_bills"])?$form["supplier_bills"]:[];
|
||
if(count($supplier_bills)>0){
|
||
//供应商订单
|
||
$BillModel = new \app\common\model\supplier\Bill;
|
||
$list = $BillModel->where(["lists.WAREHOUSEID"=>$WAREHOUSEID])->where("bill.id","in",$supplier_bills)->with(['lists'])->select();
|
||
foreach ($list as $r){
|
||
$r->isPay = 2;
|
||
$r->save();
|
||
}
|
||
$insertData["supplier_bills"] = implode(",",$supplier_bills);
|
||
}
|
||
|
||
if($editid){
|
||
$line = $this->DailyaccountModel->where(["id"=>$editid])->where("issettlement<>1")->find();
|
||
if($line){
|
||
$res = $line->save($insertData);
|
||
}else{
|
||
$this->error("记录不存在或已处理");
|
||
}
|
||
}else{
|
||
$res = $this->DailyaccountModel->save($insertData);
|
||
}
|
||
$this->success('保存成功',[$insertData,$form["date"],$res]);
|
||
}
|
||
public function back(){
|
||
$params=$this->request->post();
|
||
$id = $params["id"];
|
||
$userid = $this->auth->id;
|
||
$line = $this->DailyaccountModel->where(["id"=>$id,"issettlement"=>0])->find();
|
||
if(!$line){
|
||
$this->error("记录不存在或已处理");
|
||
}else{
|
||
$res = $line->save(["issettlement"=>2,"backmsg"=>$params["msg"],"settlement_userid"=>$userid,"examineTime"=>time()]);
|
||
}
|
||
$this->success("保存成功",$res);
|
||
}
|
||
public function examine(){
|
||
$params=$this->request->post();
|
||
$id = $params["id"];
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$userid = $this->auth->id;
|
||
Db::startTrans();
|
||
try {
|
||
//是否采用模型验证
|
||
$line = $this->DailyaccountModel->where(["id"=>$id,"issettlement"=>0])->find();
|
||
if(!$line){
|
||
$this->error("记录不存在或已处理");
|
||
}else{
|
||
if($line["supplier_bills"]){
|
||
$supplier_ids = explode(",",$line["supplier_bills"]);
|
||
$BillModel = new \app\common\model\supplier\Bill;
|
||
$list = $BillModel->where(["lists.WAREHOUSEID"=>$WAREHOUSEID])->where("bill.id","in",$supplier_ids)->with(['lists'])->select();
|
||
foreach ($list as $r){
|
||
$r->isPay = 1;
|
||
$r->save();
|
||
}
|
||
}
|
||
$bank = $this->AccountModel->where(["id"=>$line["bank_id"]])->lock(true)->find();
|
||
$account = ($bank["account"] ?? null);
|
||
$type = $this->AccounttypeModel->where(["id"=>$line["type"]])->find();
|
||
switch (($type["isin"] ?? null)) {
|
||
case 0:
|
||
$account -=$line["account"];
|
||
break;
|
||
case 1:
|
||
$account +=$line["account"];
|
||
break;
|
||
}
|
||
$bank->save(["account"=>$account]);
|
||
$res = $line->save(["issettlement"=>1,"settlement_userid"=>$userid,"examineTime"=>time()]);
|
||
}
|
||
Db::commit();
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
if ($res === false) {
|
||
$this->error(__('No rows were inserted'));
|
||
}
|
||
$this->success("入账成功",$res);
|
||
}
|
||
public function delete(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$params=$this->request->post();
|
||
$id = $params["id"];
|
||
$userid = $this->auth->id;
|
||
$line = $this->DailyaccountModel->where(["id"=>$id,"issettlement"=>2,"userid"=>$userid,"isDelete"=>0])->find();
|
||
if(!$line){
|
||
$this->error("记录不存在或已处理");
|
||
}else{
|
||
if($line["supplier_bills"]){
|
||
$supplier_ids = explode(",",$line["supplier_bills"]);
|
||
$BillModel = new \app\common\model\supplier\Bill;
|
||
$list = $BillModel->where(["lists.WAREHOUSEID"=>$WAREHOUSEID])->where("bill.id","in",$supplier_ids)->with(['lists'])->select();
|
||
foreach ($list as $r){
|
||
$r->isPay = 0;
|
||
$r->save();
|
||
}
|
||
}
|
||
$res = $line->save(["isDelete"=>1]);
|
||
}
|
||
$this->success("删除成功",$res);
|
||
}
|
||
public function export_excel(){
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$bankworksheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, "银行账户");
|
||
$spreadsheet->addSheet($bankworksheet);
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$types = $this->AccounttypeModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$params=$this->request->post();
|
||
$userid = $this->auth->id;
|
||
$storeid = $params["storeid"];
|
||
$count = 0;
|
||
$list = $this->DailyaccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"issettlement"=>'1'])->where("createTime","BETWEEN",[strtotime($params["selectTime"][0]),strtotime($params["selectTime"][1])+86399]);
|
||
if($storeid>-1){
|
||
$list->where(["STOREID"=>$storeid]);
|
||
}
|
||
$list = $list->select();
|
||
$list = json_decode(json_encode($list),true);
|
||
$user = [];
|
||
foreach ($list as $item){
|
||
if($item["userid"]>0){
|
||
array_push($user,$item["userid"]);
|
||
}
|
||
if($item["settlement_userid"]>0){
|
||
array_push($user,$item["settlement_userid"]);
|
||
}
|
||
}
|
||
$users = $this->UserModel->where("id","in",$user)->select();
|
||
|
||
foreach ($list as $k => $item){
|
||
foreach ($types as $type){
|
||
if($item["type"]==$type["id"]){
|
||
$list[$k]['type'] = $type;
|
||
}
|
||
}
|
||
foreach ($users as $user){
|
||
if($item["userid"]==$user["id"]){
|
||
$list[$k]["user_name"] = $user["real_name"];
|
||
}
|
||
if($item["settlement_userid"]==$user["id"]){
|
||
$list[$k]["settlement_username"] = $user["real_name"];
|
||
}
|
||
}
|
||
}
|
||
$StoreModel = new \app\common\model\wms\Warestore;
|
||
$userStoreModel = new \app\common\model\UserStore;
|
||
if($this->auth->check("isstaff")){
|
||
$storesList = $StoreModel->with(['employees'])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
}else{
|
||
$stores = $userStoreModel->where(["user_id"=>$userid])->select();
|
||
$storeids = [];
|
||
foreach ($stores as $r){
|
||
array_push($storeids,$r["store_id"]);
|
||
}
|
||
$storesList = $StoreModel->with(['employees'])->where("warestore.STOREID","in",$storeids)->select();
|
||
}
|
||
$banks = $this->AccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$title = '流水明细';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['序号','登记时间','收支时间','费用类目','发生对象','快递名称','单价','数量','收支金额','收入/支出','发生时间','收/支账号','备注','登记人','复核人','复核时间','凭据']
|
||
], '', 'A1' );
|
||
$lists = [];
|
||
$Paracodemodel = new \app\common\model\wms\Paracode;
|
||
$data2=$Paracodemodel->field("CODE,NAME")->where(["TYPE"=>"301"])->select();
|
||
|
||
foreach ($list as $index=> $r){
|
||
$bank_name = "";
|
||
foreach ($banks as $bank){
|
||
if($r["bank_id"]==$bank["id"]){
|
||
$bank_name = $bank["name"];
|
||
}
|
||
}
|
||
$storeName = "公司内部";
|
||
foreach ($storesList as $stores){
|
||
if($r['STOREID'] ==$stores["employees"]["STOREID"]){
|
||
$storeName = $stores["employees"]["TITLE"];
|
||
}
|
||
}
|
||
$ExpressName = "";
|
||
foreach($data2 as $express){
|
||
if($r["Express"]==$express["CODE"]){
|
||
$ExpressName = $express["NAME"];
|
||
}
|
||
}
|
||
array_push($lists,[
|
||
$index+1,
|
||
$r['createTime_text'],
|
||
$r['occurrenceTime_text'],
|
||
$r['type']['title'],
|
||
$storeName,
|
||
$ExpressName,
|
||
$r["price"],
|
||
$r["count"],
|
||
$r["account"],
|
||
$r["type"]["isin"]==1?'收入':'支出',
|
||
$r["occurrenceTime_text"],
|
||
$bank_name,
|
||
$r["remarks"],
|
||
$r["user_name"],
|
||
$r["settlement_username"],
|
||
$r["examineTime_text"],
|
||
"https://ye4s.gzxunren.com".$r["credential"]
|
||
]);
|
||
}
|
||
$worksheet->fromArray(
|
||
$lists, '', 'A2' );
|
||
$bankworksheet->fromArray(
|
||
[
|
||
['账户名称','期初','期末','收入','支出']
|
||
], '', 'A1' );
|
||
//导出时间后的账户发生金额
|
||
$types = $this->AccounttypeModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$account = $this->DailyaccountModel->field("account,bank_id,type")->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"issettlement"=>1])->where("createTime",">",strtotime($params["selectTime"][1])+86399)->select();
|
||
$lists2 = [];
|
||
foreach ($account as $r){
|
||
$ntype = [];
|
||
foreach ($types as $type){
|
||
if($type["id"]==$r["type"]){
|
||
$ntype = $type;
|
||
}
|
||
}
|
||
array_push($lists2,[$r["bank_id"],$r["account"],$ntype["isin"],$ntype["counted"]]);
|
||
}
|
||
$lists3 = [];
|
||
foreach ($list as $r){
|
||
array_push($lists3,[$r["bank_id"],$r["account"],$r['type']["isin"],$r['type']["counted"]]);
|
||
}
|
||
//账户
|
||
$listss = [];
|
||
$banks = $this->AccountModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
foreach($banks as $k => $bank){
|
||
$account = $bank['account'];
|
||
$in = 0;
|
||
$out = 0;
|
||
foreach ($lists2 as $list){
|
||
if($list[3] && $list[0]==$bank["id"]){
|
||
if($list[2]){
|
||
$account = $account-$list[1];
|
||
}else{
|
||
$account = $account+$list[1];
|
||
}
|
||
}
|
||
}
|
||
foreach ($lists3 as $list){
|
||
if($list[3] && $list[0]==$bank["id"]){
|
||
if($list[2]){
|
||
$in = $in+$list[1];
|
||
}else{
|
||
$out = $out+$list[1];
|
||
}
|
||
}
|
||
}
|
||
$account2 = $account-$in+$out;
|
||
array_push($listss,[$bank['name'],strval($account2),strval($account),strval($in),strval($out)]);
|
||
}
|
||
$list2 = ['总计',0,0,0,0];
|
||
foreach ($listss as $r){
|
||
$list2[1] += floatval($r[1]);
|
||
$list2[2] += floatval($r[2]);
|
||
$list2[3] += floatval($r[3]);
|
||
$list2[4] += floatval($r[4]);
|
||
}
|
||
foreach ($list2 as $r){
|
||
$r = strval($r);
|
||
}
|
||
array_push($listss,$list2);
|
||
|
||
$bankworksheet->fromArray(
|
||
$listss, '', 'A2' );
|
||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||
header('Content-Disposition: attachment;filename=Excel导出.xlsx');
|
||
header('Cache-Control: max-age=0');
|
||
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$write->save('php://output');
|
||
|
||
$this->success('成功',$list);
|
||
}
|
||
|
||
public function orders(){
|
||
$params = $this->request->post();
|
||
$Time = $params["time"];
|
||
$startOfMonth = strtotime(date('Y-m-d', strtotime('first day of', $Time)))*1000;
|
||
$endOfMonth = (strtotime(date('Y-m-d', strtotime('last day of', $Time)))+ 86399)*1000+999;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$Hisorder = $this->HisorderModel->field("POSTNUM")->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("sendDate","BETWEEN",[$startOfMonth,$endOfMonth]);
|
||
$storeid = isset($params["storeid"])?$params["storeid"]:0;
|
||
if($storeid>0){
|
||
$Hisorder ->where(["STOREID"=>$storeid]);
|
||
}
|
||
$page = isset($params["page"])?$params["page"]:1;
|
||
$pagesize = 200;
|
||
$offset = $pagesize*($page-1);
|
||
$Hisorder = $Hisorder->paginate($pagesize);
|
||
$lists = $Hisorder->items();
|
||
$result = ['total' => $Hisorder->total(), 'rows' => $lists];
|
||
$this->success('获取成功',$result);
|
||
}
|
||
public function export_orders(){
|
||
$params = $this->request->post();
|
||
$exportModel = new \app\common\model\export\Orders;
|
||
$Time = $params["time"];
|
||
$startOfMonth = strtotime(date('Y-m-d', strtotime('first day of', $Time)))*1000;
|
||
$endOfMonth = (strtotime(date('Y-m-d', strtotime('last day of', $Time)))+ 86399)*1000+999;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$where = "WAREHOUSEID={$WAREHOUSEID} and sendDate BETWEEN {$startOfMonth} and {$endOfMonth}";
|
||
$storeid = isset($params["storeid"])?$params["storeid"]:0;
|
||
$userid = $this->auth->id;
|
||
if($storeid>0){
|
||
$where.=" and STOREID={$storeid}";
|
||
}
|
||
$filename = time().Random::uuid();
|
||
$res = $exportModel->save(["where"=>$where,"current"=>0,"filename"=>$filename,"userid"=>$userid]);
|
||
$this->success("成功",$exportModel->id);
|
||
}
|
||
public function export_bill_task(){
|
||
$params = $this->request->post();
|
||
$BillModel = new \app\common\model\export\Bill;
|
||
$selectTime = $params['selectTime'];
|
||
$startTime= strtotime($selectTime[0]);
|
||
$endTime = strtotime($selectTime[1]);
|
||
$storeid = $params["storeid"];
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$filename = time().Random::uuid();
|
||
$userid = $this->auth->id;
|
||
$res = $BillModel->save(["storeid"=>$storeid,"startTime"=>$startTime,"endTime"=>$endTime,"current"=>0,"filename"=>$filename,"userid"=>$userid]);
|
||
$this->success("成功",$BillModel->id);
|
||
}
|
||
public function export_task_bill(){
|
||
$params = $this->request->post();
|
||
$BillModel = new \app\common\model\export\Bill;
|
||
$userid = $this->auth->id;
|
||
$taskid = $params["taskid"];
|
||
$task = $BillModel->field("count,current,status")->where(["userid"=>$userid,"id"=>$taskid])->find();
|
||
if(!$task){
|
||
$this->error("任务不存在");
|
||
}
|
||
$this->error("",$task);
|
||
}
|
||
public function export_task(){
|
||
$params = $this->request->post();
|
||
$exportModel = new \app\common\model\export\Orders;
|
||
$userid = $this->auth->id;
|
||
$taskid = $params["taskid"];
|
||
$task = $exportModel->field("count,current,status")->where(["userid"=>$userid,"id"=>$taskid])->find();
|
||
if(!$task){
|
||
$this->error("任务不存在");
|
||
}
|
||
$this->error("",$task);
|
||
}
|
||
public function downloadFile(){
|
||
$taskid = $this->request->get("taskid");
|
||
$exportModel = new \app\common\model\export\Orders;
|
||
$userid = $this->auth->id;
|
||
$task = $exportModel->where(["userid"=>$userid,"id"=>$taskid])->find();
|
||
if(!$task){
|
||
$this->error("任务不存在");
|
||
}
|
||
// 目标URL
|
||
$targetUrl = "https://file.52gol.com/export_task/{$task["filename"]}.xlsx";
|
||
|
||
// 发送302重定向
|
||
header("HTTP/1.1 302 Found");
|
||
header("Location: " . $targetUrl);
|
||
exit();
|
||
// 确保重定向后,后续代码不会继续执行
|
||
}
|
||
public function downloadbill(){
|
||
$taskid = $this->request->get("taskid");
|
||
$exportModel = new \app\common\model\export\Bill;
|
||
$userid = $this->auth->id;
|
||
$task = $exportModel->where(["userid"=>$userid,"id"=>$taskid])->find();
|
||
if(!$task){
|
||
$this->error("任务不存在");
|
||
}
|
||
// 目标URL
|
||
$targetUrl = "https://file.52gol.com/export_bill/{$task["filename"]}.xlsx";
|
||
|
||
// 发送302重定向
|
||
header("HTTP/1.1 302 Found");
|
||
header("Location: " . $targetUrl);
|
||
exit();
|
||
}
|
||
public function value_added_services_list(){
|
||
$params = $this->request->post();
|
||
$ListsModel = new \app\common\model\addedservices\Lists;
|
||
$TypesModel = new \app\common\model\addedservices\Types;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$types = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$lists = [];
|
||
$count = 0;
|
||
$Time = $params["selectTime"];
|
||
$type = isset($params["type"])?$params["type"]:0;
|
||
$storeid = isset($params["storeid"])?$params["storeid"]:0;
|
||
|
||
$startOfMonth = strtotime($Time[0]);
|
||
$endOfMonth = strtotime($Time[1])+84900;
|
||
$pagesize = 20;
|
||
$page = isset($params['page'])?$params['page']:1;
|
||
$offset = $pagesize*($page-1);
|
||
|
||
$list = $ListsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0])->where("occurrenceTime","BETWEEN",[$startOfMonth,$endOfMonth]);
|
||
if($type){
|
||
$list->where(["type"=>$type]);
|
||
}
|
||
if($storeid){
|
||
$list->where(["STOREID"=>$storeid]);
|
||
}
|
||
$list = $list->paginate($pagesize);
|
||
$lists = $list->items();
|
||
$user = [];
|
||
foreach ($lists as $item){
|
||
if($item["userid"]>0){
|
||
array_push($user,$item["userid"]);
|
||
}
|
||
}
|
||
$users = $this->UserModel->where("id","in",$user)->select();
|
||
foreach ($lists as $k => $item){
|
||
$list[$k]["credential"] = array_filter(explode(",",$item["credential"]));
|
||
foreach ($users as $user){
|
||
if($item["userid"]==$user["id"]){
|
||
$lists[$k]["user_name"] = $user["real_name"];
|
||
}
|
||
}
|
||
}
|
||
$count = $list->total();
|
||
$this->success("获取成功",[$lists,$types,$count]);
|
||
}
|
||
public function value_added_services_save(){
|
||
$params = $this->request->post();
|
||
$ListsModel = new \app\common\model\addedservices\Lists;
|
||
$info = $params["info"];
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$res = "";
|
||
if(isset($info["id"])){
|
||
$line = $ListsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"id"=>$info["id"]])->find();
|
||
if($line){
|
||
$res = $line->save([
|
||
"STOREID"=>$info["STOREID"],
|
||
"account"=>$info["account"],
|
||
"count"=>$info["count"],
|
||
"occurrenceTime"=>$info["occurrenceTime"],
|
||
"remarks"=>$info["remarks"],
|
||
"price"=>$info["price"],
|
||
"type"=>$info["type"],
|
||
"credential"=>implode($info["credential"])
|
||
]);
|
||
}else{
|
||
$this->error("修改失败,记录不存在");
|
||
}
|
||
}else{
|
||
$res = $ListsModel->save([
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"STOREID"=>$info["STOREID"],
|
||
"account"=>$info["account"],
|
||
"count"=>$info["count"],
|
||
"occurrenceTime"=>$info["occurrenceTime"],
|
||
"remarks"=>$info["remarks"],
|
||
"price"=>$info["price"],
|
||
"type"=>$info["type"],
|
||
"credential"=>implode($info["credential"]),
|
||
"createTime"=>time()
|
||
]);
|
||
}
|
||
$this->success("保存成功",$res);
|
||
}
|
||
public function value_added_services_type(){
|
||
$params = $this->request->post();
|
||
$TypesModel = new \app\common\model\addedservices\Types;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$list = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0]);
|
||
$page = isset($params['page'])?$params['page']:1;
|
||
$pagesize = 20;
|
||
$offset = $pagesize*($page-1);
|
||
$list = $list->paginate($pagesize);
|
||
$lists = $list->items();
|
||
$count = $list->total();
|
||
$this->success("获取成功",[$lists,[],$count]);
|
||
}
|
||
public function value_added_services_type_save(){
|
||
$params = $this->request->post();
|
||
$TypesModel = new \app\common\model\addedservices\Types;
|
||
$info = $params["info"];
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$res = "";
|
||
if(isset($info["id"])){
|
||
$line = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"id"=>$info["id"]])->find();
|
||
if($line){
|
||
$res = $line->save(["title"=>$info["title"]]);
|
||
}else{
|
||
$this->error("修改失败,分类不存在");
|
||
}
|
||
}else{
|
||
$res = $TypesModel->save(["title"=>$info["title"],"WAREHOUSEID"=>$WAREHOUSEID]);
|
||
}
|
||
$this->success("保存成功",$res);
|
||
}
|
||
public function value_added_services_type_delete(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$TypesModel = new \app\common\model\addedservices\Types;
|
||
$id = isset($params["id"])?$params["id"]:0;
|
||
$line = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"id"=>$id])->find();
|
||
if($line){
|
||
$line->save(["isDelete"=>1]);
|
||
}else{
|
||
$this->error("删除失败,分类不存在");
|
||
}
|
||
$this->success("删除成功",$res);
|
||
}
|
||
public function value_added_services_delete(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$ListsModel = new \app\common\model\addedservices\Lists;
|
||
$id = isset($params["id"])?$params["id"]:0;
|
||
$line = $ListsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"id"=>$id])->find();
|
||
if($line){
|
||
$line->save(["isDelete"=>1]);
|
||
}else{
|
||
$this->error("删除失败,记录不存在");
|
||
}
|
||
$this->success("删除成功",$res);
|
||
}
|
||
public function bank_account(){
|
||
$params = $this->request->post();
|
||
$TypesModel = new \app\common\model\bank\Account;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
if($this->auth->rePassword==0){
|
||
$this->success("请初始化密码",[-1]);
|
||
}
|
||
if($this->auth->rePassword==0&&$params["passcode"]){
|
||
$_user = $this->UserModel->get($this->auth->id);
|
||
$_user->verificationfailure=0;
|
||
$_user->verificationtime = time();
|
||
$_user->rePassword = 1;
|
||
$_user->password = md5(md5($params["passcode"]).$this->auth->salt);
|
||
$_user->save();
|
||
}
|
||
if(!isset($params["passcode"])||!$params["passcode"]){
|
||
$this->success("未验证密码",[0]);
|
||
}
|
||
$verificationfailure = $this->auth->verificationfailure;
|
||
$verificationtime = $this->auth->verificationtime;
|
||
if($verificationfailure>3 && $verificationtime>time()-600){
|
||
$this->error("密码验证失败超过3次,请在".date('Y-m-d H:i:s',$verificationtime+600)."后再试");
|
||
}
|
||
if(md5(md5($params["passcode"]).$this->auth->salt)!=$this->auth->password){
|
||
$_user = $this->UserModel->get($this->auth->id);
|
||
$_user->verificationfailure+=1;
|
||
$_user->verificationtime = time();
|
||
$_user->save();
|
||
$this->error("密码错误",[0]);
|
||
}else{
|
||
$_user = $this->UserModel->get($this->auth->id);
|
||
$_user->verificationfailure=0;
|
||
$_user->save();
|
||
}
|
||
$list = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0]);
|
||
$page = isset($params['page'])?$params['page']:1;
|
||
$pagesize = 20;
|
||
$offset = $pagesize*($page-1);
|
||
$list = $list->paginate($pagesize);
|
||
$lists = $list->items();
|
||
$count = $list->total();
|
||
$allcount = $TypesModel->field("sum(account) as allaccount")->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0])->find();
|
||
$this->success("获取成功",[1,$lists,$count,$allcount]);
|
||
}
|
||
public function bank_account_save(){
|
||
$params = $this->request->post();
|
||
$TypesModel = new \app\common\model\bank\Account;
|
||
$info = $params["info"];
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$res = "";
|
||
if(isset($info["id"])){
|
||
$line = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"id"=>$info["id"]])->find();
|
||
if($line){
|
||
$res = $line->save(["name"=>$info["name"]]);
|
||
}else{
|
||
$this->error("修改失败,分类不存在");
|
||
}
|
||
}else{
|
||
$res = $TypesModel->save(["name"=>$info["name"],"WAREHOUSEID"=>$WAREHOUSEID]);
|
||
}
|
||
$this->success("保存成功",$res);
|
||
}
|
||
public function bank_account_delete(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$ListsModel = new \app\common\model\bank\Account;
|
||
$id = isset($params["id"])?$params["id"]:0;
|
||
$line = $ListsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"id"=>$id])->find();
|
||
if($line){
|
||
$line->save(["isDelete"=>1]);
|
||
}else{
|
||
$this->error("删除失败,记录不存在");
|
||
}
|
||
$this->success("删除成功",$res);
|
||
}
|
||
public function type_setting(){
|
||
$params = $this->request->post();
|
||
$TypesModel = new \app\common\model\Accounttype;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$list = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0]);
|
||
$page = isset($params['page'])?$params['page']:1;
|
||
$pagesize = 20;
|
||
$offset = $pagesize*($page-1);
|
||
$list = $list->order("id","desc")->paginate($pagesize);
|
||
$lists = $list->items();
|
||
$count = $list->total();
|
||
$this->success("获取成功",[$lists,$count]);
|
||
}
|
||
public function type_setting_save(){
|
||
$params = $this->request->post();
|
||
$TypesModel = new \app\common\model\Accounttype;
|
||
$info = $params["info"];
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$res = "";
|
||
if(isset($info["id"])){
|
||
$line = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"id"=>$info["id"]])->find();
|
||
if($line){
|
||
$res = $line->save([
|
||
"title"=>$info["title"],
|
||
"counted"=>$info["counted"],
|
||
"isExpress"=>$info["isExpress"],
|
||
"isExpressOut"=>$info["isExpressOut"],
|
||
"isInit"=>$info["isInit"],
|
||
"isin"=>$info["isin"]
|
||
]);
|
||
}else{
|
||
$this->error("修改失败,分类不存在");
|
||
}
|
||
}else{
|
||
$res = $TypesModel->save([
|
||
"title"=>$info["title"],
|
||
"counted"=>$info["counted"],
|
||
"isExpress"=>$info["isExpress"],
|
||
"isExpressOut"=>$info["isExpressOut"],
|
||
"isInit"=>$info["isInit"],
|
||
"isin"=>$info["isin"],
|
||
"WAREHOUSEID"=>$WAREHOUSEID
|
||
]);
|
||
}
|
||
$this->success("保存成功",$res);
|
||
}
|
||
public function type_setting_delete(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$ListsModel = new \app\common\model\Accounttype;
|
||
$id = isset($params["id"])?$params["id"]:0;
|
||
$line = $ListsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"id"=>$id])->find();
|
||
if($line){
|
||
$line->save(["isDelete"=>1]);
|
||
}else{
|
||
$this->error("删除失败,记录不存在");
|
||
}
|
||
$this->success("删除成功",$res);
|
||
}
|
||
public function statistics(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$Paracodemodel = new \app\common\model\wms\Paracode;
|
||
$selectTime = [strtotime($params['selectTime'][0]),
|
||
strtotime($params['selectTime'][1])+853900];
|
||
$type = isset($params['type'])?$params['type']:0;
|
||
$data = $this->DailyaccountModel->field('type,sum(account) as account')->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"issettlement"=>1]);
|
||
if(!$type){
|
||
$data->where("occurrenceTime","BETWEEN",$selectTime);
|
||
}else{
|
||
$data->where("payTime","BETWEEN",$selectTime);
|
||
}
|
||
$data = $data->group("type")->order("account","desc")->select();
|
||
$types = $this->AccounttypeModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$res = [];
|
||
$resin = [];
|
||
$resout = [];
|
||
$isouttypes = [];
|
||
$POSTCODE=$Paracodemodel->field("CODE,NAME")->where(["TYPE"=>"301"])->select();
|
||
foreach ($data as $r){
|
||
$type = [];
|
||
foreach ($types as $rr){
|
||
if($rr["id"]==$r["type"]){
|
||
$type = $rr;
|
||
}
|
||
}
|
||
$data2 = [];
|
||
if($type["isExpressOut"]==1){
|
||
|
||
$data2 = $this->DailyaccountModel->field('Express,sum(account) as account')->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"issettlement"=>1,"type"=>$type["id"]])->where("createTime","BETWEEN",$selectTime);
|
||
if(!$type){
|
||
$data2->where("occurrenceTime","BETWEEN",$selectTime);
|
||
}else{
|
||
$data2->where("payTime","BETWEEN",$selectTime);
|
||
}
|
||
$data2 = $data2->group("Express")->order("account","desc")->select();
|
||
foreach ($data2 as $kk => $rr){
|
||
foreach ($POSTCODE as $rrr){
|
||
if($rrr["CODE"]==$rr["Express"]){
|
||
$data2[$kk]["POSTNAME"] = $rrr["NAME"];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
array_push($res,["type"=>$type,"account"=>$type["isin"]==1?$r["account"]:-$r["account"],"POST"=>$data2]);
|
||
if($type["isin"]==1){
|
||
array_push($resin,["type"=>$type,"account"=>$type["isin"]==1?$r["account"]:-$r["account"],"POST"=>$data2]);
|
||
}else{
|
||
array_push($resout,["type"=>$type,"account"=>$type["isin"]==1?$r["account"]:-$r["account"],"POST"=>$data2]);
|
||
}
|
||
}
|
||
$inaccount = 0;
|
||
$outaccount = 0;
|
||
$allaccount = 0;
|
||
foreach ($res as $r){
|
||
$allaccount=bcadd($allaccount, $r["account"], 2);
|
||
if($r["type"]["isin"]==1){
|
||
$inaccount=bcadd($inaccount, $r["account"], 2);
|
||
}else{
|
||
$outaccount=bcadd($outaccount, $r["account"], 2);
|
||
}
|
||
}
|
||
$this->success("获取成功",[[$resin,$resout],[$inaccount,$outaccount,$allaccount]]);
|
||
}
|
||
|
||
private function getDailyStartTimestamps($startTime, $endTime)
|
||
{
|
||
// 将结束时间戳转为第二天开始时间戳
|
||
$endTime = strtotime(date('Y-m-d', $endTime)) + 86400;
|
||
// 计算时间戳差值
|
||
$diff = $endTime - $startTime;
|
||
// 计算天数
|
||
$days = ceil($diff / 86400);
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>开始时间戳以天为数组
|
||
$timestamps = [];
|
||
for ($i = 0; $i < $days; $i++) {
|
||
$timestamps[]['date'] = $startTime + $i * 86400;
|
||
}
|
||
return $timestamps;
|
||
}
|
||
|
||
public function supplier_list(){
|
||
$params = $this->request->post();
|
||
$TypesModel = new \app\common\model\supplier\Lists;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$list = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0]);
|
||
$page = isset($params['page'])?$params['page']:1;
|
||
$pagesize = 20;
|
||
$offset = $pagesize*($page-1);
|
||
$list = $list->paginate($pagesize);
|
||
$lists = $list->items();
|
||
$count = $list->total();
|
||
$this->success("获取成功",[$lists,[],$count]);
|
||
}
|
||
public function supplier_list_all(){
|
||
$params = $this->request->post();
|
||
$TypesModel = new \app\common\model\supplier\Lists;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$list = $TypesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0]);
|
||
$list = $list->select();
|
||
$this->success("获取成功",$list);
|
||
}
|
||
public function supplier_list_save(){
|
||
$params = $this->request->post();
|
||
$TypesModel = new \app\common\model\supplier\Lists;
|
||
$info = $params["info"];
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$res = $TypesModel->save(["name"=>$info["name"],"WAREHOUSEID"=>$WAREHOUSEID]);
|
||
$this->success("保存成功",$res);
|
||
}
|
||
public function supplier_list_delete(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$ListsModel = new \app\common\model\supplier\Lists;
|
||
$id = isset($params["id"])?$params["id"]:0;
|
||
$line = $ListsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"isDelete"=>0,"id"=>$id])->find();
|
||
if($line){
|
||
$line->save(["isDelete"=>1]);
|
||
}else{
|
||
$this->error("删除失败,记录不存在");
|
||
}
|
||
$this->success("删除成功",$res);
|
||
}
|
||
public function export_supplier_excel(){
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$BillModel = new \app\common\model\supplier\Bill;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$params=$this->request->post();
|
||
$userid = $this->auth->id;
|
||
$storeid = $params["storeid"];
|
||
$list = $BillModel->where(["lists.WAREHOUSEID"=>$WAREHOUSEID])->where("occTime","BETWEEN",[strtotime($params["selectTime"][0]),strtotime($params["selectTime"][1])+86399])->with(['lists','user']);
|
||
if($params['is_examine']==0){
|
||
$list->where(["isPay"=>0]);
|
||
}
|
||
if($params['storeid']>0){
|
||
$list->where(["pid"=>$params['storeid']]);
|
||
}
|
||
$page = isset($params['page'])?$params['page']:1;
|
||
$lists = $list->select();
|
||
foreach ($lists as $r){
|
||
$r["items"] = json_decode($r["items"],true);
|
||
$r["credential"] = explode(",",$r["credential"]);
|
||
}
|
||
$list_data = [];
|
||
foreach ($lists as $r){
|
||
switch($r["isPay"]){
|
||
case 0:
|
||
$status = "未结清";
|
||
break;
|
||
case 1:
|
||
$status = "已结清";
|
||
break;
|
||
case 2:
|
||
$status = "待结算";
|
||
break;
|
||
default:
|
||
$status = "未知";
|
||
}
|
||
$credential = $r["credential"];
|
||
$credentials = [];
|
||
foreach ($credential as $rr){
|
||
array_push($credentials,"https://ye4s.gzxunren.com".$rr);
|
||
}
|
||
$items = $r["items"];
|
||
$credential = implode(",",$credentials);
|
||
foreach ($items as $rr){
|
||
array_push($list_data,[$r["id"],$r["createTime_text"],$r["occTime_text"],$status,$r["lists"]["name"],$rr["name"],$rr["price"],$rr["count"],$rr["price"]*$rr["count"],$r["remarks"],$credential,$r["user"]["real_name"]]);
|
||
}
|
||
}
|
||
$title = '送货明细';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['送货单序号','登记时间','送货时间','状态','供应商','名称','单价','数量','金额','备注','发生凭据','登记人']
|
||
], '', 'A1' );
|
||
|
||
$worksheet->fromArray(
|
||
$list_data, '', 'A2' );
|
||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||
header('Content-Disposition: attachment;filename=Excel导出.xlsx');
|
||
header('Cache-Control: max-age=0');
|
||
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$write->save('php://output');
|
||
exit();
|
||
}
|
||
|
||
public function supplier_bill(){
|
||
$BillModel = new \app\common\model\supplier\Bill;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$params = $this->request->post();
|
||
$list = [];
|
||
$count = 0;
|
||
$count2 = 0;
|
||
$list = $BillModel->where(["lists.WAREHOUSEID"=>$WAREHOUSEID])->where("occTime","BETWEEN",[strtotime($params["selectTime"][0]),strtotime($params["selectTime"][1])+86399])->with(['lists','user']);
|
||
if($params['is_examine']==0){
|
||
$list->where(["isPay"=>0]);
|
||
}
|
||
if($params['storeid']>0){
|
||
$list->where(["pid"=>$params['storeid']]);
|
||
}
|
||
$page = isset($params['page'])?$params['page']:1;
|
||
$pagesize = isset($params["pagesize"])?$params["pagesize"]:20;
|
||
$offset = $pagesize*($page-1);
|
||
$list = $list->paginate($pagesize);
|
||
$lists = $list->items();
|
||
foreach ($lists as $r){
|
||
$r["items"] = json_decode($r["items"],true);
|
||
$r["credential"] = explode(",",$r["credential"]);
|
||
}
|
||
$count = $list->total();
|
||
$count2 = $BillModel->where(["lists.WAREHOUSEID"=>$WAREHOUSEID,"isPay"=>0])->with(['lists'])->where("occTime","BETWEEN",[strtotime($params["selectTime"][0]),strtotime($params["selectTime"][1])+86399])->count();
|
||
$this->success('获取成功',[$lists,$count,$count2]);
|
||
}
|
||
public function supplier_bill_save(){
|
||
$params = $this->request->post();
|
||
$BillModel = new \app\common\model\supplier\Bill;
|
||
$ListsModel = new \app\common\model\supplier\Lists;
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$editid = $params["editid"];
|
||
$info = $params['form'];
|
||
$p = $ListsModel->where(["id"=>$info['pid'],"WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if(!$p){
|
||
$this->error("供应商不存在,请刷新重新登记");
|
||
}
|
||
$userid = $this->auth->id;
|
||
$res = "";
|
||
$account = 0;
|
||
$items = json_encode($info["items"]);
|
||
foreach ($info["items"] as $r){
|
||
$account+=$r["price"]*$r["count"];
|
||
}
|
||
$credential = implode(",",$info["credential"]);
|
||
$occTime = strtotime($info["occTime"]);
|
||
if(isset($info["id"])){
|
||
$line = $BillModel->where(["id"=>$info["id"],"isPay"=>0])->find();
|
||
if($line){
|
||
$res = $line->save([
|
||
"account"=>$account,
|
||
"items"=>$items,
|
||
"pid"=>$info["pid"],
|
||
"occTime"=>$occTime,
|
||
"userid"=>$userid,
|
||
"createTime"=>time(),
|
||
"credential"=>$credential,
|
||
"trans_orderid"=>$info["trans_orderid"],
|
||
"remarks"=>$info["remarks"]
|
||
]);
|
||
}else{
|
||
$this->error("修改失败,送货单不存在,或不可更改");
|
||
}
|
||
}else{
|
||
$res = $BillModel->save([
|
||
"account"=>$account,
|
||
"items"=>$items,
|
||
"pid"=>$info["pid"],
|
||
"occTime"=>$occTime,
|
||
"userid"=>$userid,
|
||
"createTime"=>time(),
|
||
"credential"=>$credential,
|
||
"trans_orderid"=>$info["trans_orderid"],
|
||
"remarks"=>$info["remarks"]
|
||
]);
|
||
}
|
||
$this->success("保存成功",$res);
|
||
}
|
||
public function supplier_bill_delete(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$BillModel = new \app\common\model\supplier\Bill;
|
||
$id = isset($params["id"])?$params["id"]:0;
|
||
$line = $BillModel->where(["lists.WAREHOUSEID"=>$WAREHOUSEID,"bill.id"=>$id])->with(['lists'])->find();
|
||
$res = "";
|
||
if($line){
|
||
$res = $line->delete();
|
||
}else{
|
||
$this->error("删除失败,记录不存在");
|
||
}
|
||
$this->success("删除成功",$res);
|
||
}
|
||
public function supplier_item_import(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$file = request()->file('file'); // 获取上传的文件
|
||
if ($file) {
|
||
$filePath = $file->getRealPath(); // 获取文件路径
|
||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath); // 加载 XLSX 文件
|
||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); // 读取数据
|
||
$save_data_arr = [];
|
||
foreach($sheetData as $k => $r){
|
||
$save_data = ["name"=>$r["A"],"price"=>$r["B"],"count"=>$r["C"],"id"=>$k];
|
||
if($k>1){
|
||
array_push($save_data_arr,$save_data);
|
||
}
|
||
}
|
||
$this->success("上传成功",$save_data_arr);
|
||
}
|
||
$this->error("上传失败");
|
||
}
|
||
public function receivable_import(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$file = request()->file('file'); // 获取上传的文件
|
||
if ($file) {
|
||
$filePath = $file->getRealPath(); // 获取文件路径
|
||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath); // 加载 XLSX 文件
|
||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); // 读取数据
|
||
/*$save_data_arr = [];
|
||
foreach($sheetData as $k => $r){
|
||
$save_data = ["name"=>$r["A"],"price"=>$r["B"],"count"=>$r["C"],"id"=>$k];
|
||
if($k>1){
|
||
array_push($save_data_arr,$save_data);
|
||
}
|
||
}*/
|
||
$this->success("上传成功",$sheetData);
|
||
}
|
||
$this->error("上传失败");
|
||
}
|
||
}
|