提交 9f861c41 authored 作者: 李大见's avatar 李大见

yhwx

上级
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class shop extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'shop:state';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// 修改已过期的店铺状态
$find_shop = DB::table('shop')
->where('shop_state', 1)
->get()->toArray();
if (!empty($find_shop)) {
foreach ($find_shop as $key => $value) {
if ($value->shop_opening_type == 1) {
if (strtotime($value->shop_on_trial_end_time)<= time()) {//已过期的试用店铺
$update_data['shop_state'] = 2;
}
} elseif ($value->shop_opening_type == 2) {
if (strtotime($value->shop_opening_end_time)<= time()) {//已过期的正式店铺
$update_data['shop_state'] = 2;
}
} else {
$update_data['shop_opening_type'] = 1;
$update_data['shop_state'] = 2;
}
$update_data['shop_update_time'] = date('Y-m-d H:i:s');
$update_data_res = DB::table('shop')
->where('shop_id', $value->shop_id)
->update($update_data);
}
}
}
}
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
Commands\shop::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
$schedule->command('shop:state')->everyMinute(); //修改门店信息
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
<?php
namespace App\ExcelTemp;
trait ExcelTemp
{
public function getActions ()
{
$action = [
['action_name' => '订单列表', 'action_value' => 'WashOrderindex'],//订单管理
['action_name' => '采购管理', 'action_value' => 'PurchaseOrderindex'],//采购管理
['action_name' => '调拨单', 'action_value' => 'TransferringOrdersindex'],//调拨单
['action_name' => '绩效明细-工单', 'action_value' => 'OrderPerformance'],//工单绩效管理
['action_name' => '绩效明细-技师', 'action_value' => 'TechnicianPerformance'],//技师绩效管理
['action_name' => '绩效明细-详情', 'action_value' => 'DetailPerformance'],//详情绩效管理
['action_name' => '应收应付', 'action_value' => 'receivablePayindex'],//应收应付
['action_name' => '商品列表', 'action_value' => 'GoodsListindex'],//商品
['action_name' => '会员客户', 'action_value' => 'MemberListindex'],//会员客户
['action_name' => '销售员绩效', 'action_value' => 'ProPerformanceordersp'],//销售员绩效
['action_name' => '工单列表', 'action_value' => 'WashWork'],//工单列表
['action_name' => '售后列表', 'action_value' => 'WashAfterSales'],//售后列表
['action_name' => '罚单列表', 'action_value' => 'WashViolation'],//罚单列表
];
return $action;
}
public function getField ($param)
{
$filed = [
'WashOrderindex' => [//订单管理
['field_name' => '订单单号', 'field_value' => 'ord_order_number'],
['field_name' => '订单状态', 'field_value' => 'ord_wor_state'],
['field_name' => '订单来源', 'field_value' => 'ord_source'],
['field_name' => '商品名称', 'field_value' => 'orgo_goo_name'],
['field_name' => '商品单位', 'field_value' => 'orgo_goo_unit'],
['field_name' => '商品数量', 'field_value' => 'orgo_goo_quantity'],
['field_name' => '检索编码', 'field_value' => 'orgo_goo_goods_encode'],
['field_name' => '仓库', 'field_value' => 'ord_ware_id'],
['field_name' => '订单总额(元)', 'field_value' => 'ord_order_price'],
['field_name' => '实付金额(元)', 'field_value' => 'ord_actual_price'],
['field_name' => '结算状态', 'field_value' => 'ord_state'],
['field_name' => '结算方式', 'field_value' => 'ord_payment_way'],
['field_name' => '结算时间', 'field_value' => 'ord_settlement_time'],
['field_name' => '会员姓名', 'field_value' => 'orcl_name'],
['field_name' => '会员电话', 'field_value' => 'orcl_phone'],
['field_name' => '车牌号', 'field_value' => 'orcl_car_num'],
['field_name' => '品牌车系', 'field_value' => 'orcl_car_brand_series'],
['field_name' => '客户类型', 'field_value' => 'ord_type'],//
['field_name' => '客户来源', 'field_value' => 'orcl_mem_source'], //
['field_name' => '车主姓名', 'field_value' => 'orcl_carowner_name'],//
['field_name' => '车主电话', 'field_value' => 'orcl_carowner_phone'],//
['field_name' => '销售人', 'field_value' => 'orcl_sales_adm_id'],//
['field_name' => '录单人', 'field_value' => 'ord_create_id'],//
['field_name' => '预约时间', 'field_value' => 'orcl_appoint_time'],//
['field_name' => '创建时间', 'field_value' => 'ord_create_time'],//
['field_name' => '施工门店', 'field_value' => 'ord_shop_id'],//
],
/*'PurchaseOrderindex' => [//采购管理
['field_name' => '采购单号', 'field_value' => 'cg_number'],
['field_name' => '合同单号', 'field_value' => 'contract_number'],
['field_name' => '采购状态', 'field_value' => 'cg_state'],
['field_name' => '创建时间', 'field_value' => 'create_time'],
['field_name' => '供应商', 'field_value' => 'chun_unit_name'],
['field_name' => '商品名称', 'field_value' => 'goods_name'],
['field_name' => '商品编码', 'field_value' => 'goods_number'],
['field_name' => '数量', 'field_value' => 'goods_num'],
['field_name' => '采购单价', 'field_value' => 'univalence'],
['field_name' => '金额', 'field_value' => 'money'],
['field_name' => '付款方式', 'field_value' => 'cg_paymentype'],
['field_name' => '业务类型', 'field_value' => 'business_type'],
/*['field_name' => '入库单号', 'field_value' => 'rk_number'],
['field_name' => '入库时间', 'field_value' => 'arrival_time'],
['field_name' => '仓库名称', 'field_value' => 'ware_name'],
/*['field_name' => '入库状态', 'field_value' => 'rk_state'],
['field_name' => '入库类型', 'field_value' => 'rk_type'],//
['field_name' => '入库数量', 'field_value' => 'ruku_num'], //
],*/
'PurchaseOrderindex' => [//采购管理
['field_name' => '采购单号', 'field_value' => 'cg_number'],
['field_name' => '供应商', 'field_value' => 'chun_unit_name'],
['field_name' => '仓库', 'field_value' => 'ware_name'],
['field_name' => '创建人', 'field_value' => 'cg_creator'],
//['field_name' => '采购总数', 'field_value' => 'num'],
['field_name' => '采购总价', 'field_value' => 'cg_amount'],
['field_name' => '采购状态', 'field_value' => 'cg_state'],
['field_name' => '结算状态', 'field_value' => 'cg_settlementype'],
['field_name' => '采购日期', 'field_value' => 'cg_purchasetime'],
['field_name' => '创建日期', 'field_value' => 'create_time'],
['field_name' => '采购备注', 'field_value' => 'cg_remark'],
['field_name' => '联系人', 'field_value' => 'contact_name'],
['field_name' => '联系电话', 'field_value' => 'contact_phone'],
['field_name' => '交货方式', 'field_value' => 'cg_delivertype'],
['field_name' => '票据类型', 'field_value' => 'cg_invoicetype'],
['field_name' => '结算方式', 'field_value' => 'cg_paymentype'],
['field_name' => '审核人', 'field_value' => 'financial_user'],//
],
'TransferringOrdersindex' => [//调拨单
['field_name' => '单号', 'field_value' => 'tror_number'],
['field_name' => '调出仓库', 'field_value' => 'tror_out_ware_id'],
['field_name' => '调入仓库', 'field_value' => 'tror_in_ware_id'],
['field_name' => '商品名称', 'field_value' => 'goo_name'],
['field_name' => '商品单位', 'field_value' => 'goo_unit'],
['field_name' => '检索编码', 'field_value' => 'goo_goods_encode'],
['field_name' => '商品类型', 'field_value' => 'goo_cate_name'],
['field_name' => '调拨数量', 'field_value' => 'trog_stock_number'],
['field_name' => '创建人', 'field_value' => 'tror_create_id'],
['field_name' => '送货人', 'field_value' => 'tror_service_adm_id'],
['field_name' => '创建时间', 'field_value' => 'tror_create_time'],
['field_name' => '状态', 'field_value' => 'tror_state'],
['field_name' => '备注', 'field_value' => 'tror_remark'],
['field_name' => '商品单价', 'field_value' => 'wago_goo_price'],
['field_name' => '商品总价', 'field_value' => 'all_price'],
],
'receivablePayindex' => [//应收应付
['field_name' => '单号', 'field_value' => 'recpay_original_number'],
['field_name' => '类型', 'field_value' => 'recpay_type'],
['field_name' => '创建时间', 'field_value' => 'recpay_create_time'],
['field_name' => '会员类型', 'field_value' => 'recpay_client_type'],
['field_name' => '会员名称', 'field_value' => 'recpay_client_name'],
['field_name' => '应收金额', 'field_value' => 'recpay_receivable_price'],
['field_name' => '欠收金额', 'field_value' => 'recpay_arrears_price'],
['field_name' => '实收金额', 'field_value' => 'recpay_actual_price'],
['field_name' => '成本', 'field_value' => 'recpay_cost_price'],
['field_name' => '绩效', 'field_value' => 'recpay_receivable_pay'],
['field_name' => '抹零', 'field_value' => 'recpay_zero_price'],
['field_name' => '盈利', 'field_value' => 'recpay_profit'],
['field_name' => '状态', 'field_value' => 'recpay_state'],
['field_name' => '施工门店', 'field_value' => 'orcl_business_name'],
],
'GoodsListindex' => [//商品
['field_name' => '序列号', 'field_value' => 'goo_id'],
['field_name' => '商品名称', 'field_value' => 'goo_name'],
['field_name' => '检索编号', 'field_value' => 'goo_goods_encode'],
['field_name' => '商品别名', 'field_value' => 'goaf_another_name'],
['field_name' => '商品品类', 'field_value' => 'goo_cate_name'],
['field_name' => '商品品牌', 'field_value' => 'goo_bra_name'],
['field_name' => '品牌系列', 'field_value' => 'goo_brse_id'],
['field_name' => '零售价', 'field_value' => 'goo_price'],
['field_name' => '批发价', 'field_value' => 'goo_wholesale_price'],
['field_name' => '采购价', 'field_value' => 'goo_purchase_price'],
['field_name' => '单位', 'field_value' => 'goo_unit'],
['field_name' => '商品属性', 'field_value' => 'goo_attribute'],
['field_name' => '单位长度', 'field_value' => 'goo_unit_conversion'],
],
'OrderPerformance' => [//工单绩效管理
['field_name' => '工单单号', 'field_value' => 'pewo_wor_number'],
['field_name' => '订单单号', 'field_value' => 'pewo_ord_order_number'],
['field_name' => '服务名称', 'field_value' => 'pewo_sepr_name'],
['field_name' => '审核时间', 'field_value' => 'pewo_create_time'],
['field_name' => '商品名称', 'field_value' => 'pewo_goo_name'],
['field_name' => '订单金额', 'field_value' => 'ord_order_price'],
['field_name' => '服务技师', 'field_value' => 'pewo_service_adm_name'],
['field_name' => '车辆牌照', 'field_value' => 'wocl_car_num'],
['field_name' => '品牌车系', 'field_value' => 'pewo_car_brand_series'],
['field_name' => '综合得分', 'field_value' => 'pewo_score'],
['field_name' => '绩效金额', 'field_value' => 'pewo_performance_total_price'],
],
'TechnicianPerformance' => [//技师绩效管理
['field_name' => '技师姓名', 'field_value' => 'pewo_service_adm_name'],
['field_name' => '联系电话', 'field_value' => 'adm_phone'],
['field_name' => '技师职级', 'field_value' => 'grle_name'],
['field_name' => '工单数量', 'field_value' => 'work_quantity'],
['field_name' => '绩效总金额', 'field_value' => 'performance_total_price'],
],
'DetailPerformance' => [//详情绩效管理
['field_name' => '工单号', 'field_value' => 'pewo_wor_number'],
['field_name' => '订单号', 'field_value' => 'pewo_ord_order_number'],
['field_name' => '工单组长', 'field_value' => 'service_adm_name'],
['field_name' => '施工组员', 'field_value' => 'team_service_adm_name'],
['field_name' => '车辆牌照', 'field_value' => 'wocl_car_num'],
['field_name' => '施工车辆', 'field_value' => 'pewo_car_brand_series'],
['field_name' => '核算时间', 'field_value' => 'pewo_create_time'],
['field_name' => '施工项目', 'field_value' => 'pewo_sepr_name'],
['field_name' => '施工产品', 'field_value' => 'pewo_goo_name'],
['field_name' => '综合得分', 'field_value' => 'pewo_score'],
['field_name' => '绩效金额', 'field_value' => 'pewo_performance_total_price'],
['field_name' => '派单时间', 'field_value' => 'wor_create_time'],
['field_name' => '验车时间', 'field_value' => 'vaca_create_time'],
['field_name' => '施工完成时间', 'field_value' => 'wor_achieve_time'],
['field_name' => '完成工单耗时', 'field_value' => 'consuming'],
['field_name' => '售后订单商品', 'field_value' => 'afsi_goo_name'],
['field_name' => '客户姓名', 'field_value' => 'wocl_name'],
['field_name' => '客户电话', 'field_value' => 'wocl_phone'],
['field_name' => '省', 'field_value' => 'wocl_province'],
['field_name' => '市', 'field_value' => 'wocl_city'],
['field_name' => '县', 'field_value' => 'wocl_county'],
['field_name' => '详细地址', 'field_value' => 'wocl_address'],
['field_name' => '施工门店', 'field_value' => 'wor_address_name'],
['field_name' => '施工说明', 'field_value' => 'wor_explain'],
['field_name' => '销售人员', 'field_value' => 'wocl_sales_adm_name'],
],
'MemberListindex' => [//会员客户
['field_name' => '会员姓名', 'field_value' => 'mem_name'],
['field_name' => '性别', 'field_value' => 'mem_sex'],
['field_name' => '联系电话', 'field_value' => 'mem_phone'],
['field_name' => '联系地址', 'field_value' => 'mem_address'],
['field_name' => '车牌号', 'field_value' => 'mem_car_num'],
['field_name' => '品牌车系', 'field_value' => 'mem_car_series'],
['field_name' => '会员级别', 'field_value' => 'mem_bership'],
['field_name' => '会员等级', 'field_value' => 'mem_level'],
['field_name' => '生日', 'field_value' => 'mem_birthday'],
['field_name' => '来源', 'field_value' => 'mem_source'],
['field_name' => '欠款金额', 'field_value' => 'mem_arrears'],
['field_name' => '余额', 'field_value' => 'mem_rec_banlance'],
['field_name' => '积分', 'field_value' => 'mem_points'],
['field_name' => '创建人', 'field_value' => 'mem_create_id'],
['field_name' => '邀请人', 'field_value' => 'mem_fid'],
],
'ProPerformanceordersp' => [//销售员绩效
['field_name' => '订单单号', 'field_value' => 'ord_order_number'],
['field_name' => '订单时间', 'field_value' => 'ord_create_time'],
['field_name' => '销售员', 'field_value' => 'orcl_sales_adm_name'],
['field_name' => '订单金额', 'field_value' => 'ord_order_price'],
['field_name' => '订单状态', 'field_value' => 'ord_wor_state_name'],
['field_name' => '结算状态', 'field_value' => 'ord_pay_state_name'],
['field_name' => '绩效金额', 'field_value' => 'performance'],
['field_name' => '绩效详情', 'field_value' => 'new_order_goods'],
['field_name' => '来源', 'field_value' => 'ord_source_name'],
['field_name' => '支付方式', 'field_value' => 'ord_payment_name'],
['field_name' => '计算方式', 'field_value' => 'ord_saleman_type'],
],
'WashWork' => [//工单列表
['field_name' => '订单单号', 'field_value' => 'wor_order_number'],
['field_name' => '工单编号', 'field_value' => 'wor_number'],
['field_name' => '派单时间', 'field_value' => 'wor_create_time'],
['field_name' => '预约时间', 'field_value' => 'wor_appoint_time'],
['field_name' => '施工门店', 'field_value' => 'shop_store_name'],
['field_name' => '工单类型', 'field_value' => 'ord_new_type_name'],
['field_name' => '施工技师', 'field_value' => 'service_adm_name'],
['field_name' => '工单商品', 'field_value' => 'woek_good'],
['field_name' => '客户姓名', 'field_value' => 'wocl_name'],
['field_name' => '联系电话', 'field_value' => 'wocl_phone'],
['field_name' => '省份', 'field_value' => 'wocl_province'],
['field_name' => '城市', 'field_value' => 'wocl_city'],
['field_name' => '区县', 'field_value' => 'wocl_county'],
['field_name' => '详细地址', 'field_value' => 'wocl_address'],
['field_name' => '车牌号', 'field_value' => 'wocl_car_num'],
['field_name' => '车辆信息', 'field_value' => 'wocl_car_brand_series']
],
'WashAfterSales' => [//售后列表
['field_name' => '订单单号', 'field_value' => 'afsl_order_number'],
['field_name' => '售后编号', 'field_value' => 'afsl_after_number'],
['field_name' => '创建时间', 'field_value' => 'afsl_create_time'],
['field_name' => '预约时间', 'field_value' => 'afsl_reservation_time'],
['field_name' => '订单项目', 'field_value' => 'wash_after_sale_items'],
['field_name' => '售后耗材', 'field_value' => 'afsl_goods'],
['field_name' => '售后标签', 'field_value' => 'afsl_lab_name'],
['field_name' => '售后备注', 'field_value' => 'afsl_remark'],
['field_name' => '总金额', 'field_value' => 'afsl_actual_price'],
['field_name' => '会员姓名', 'field_value' => 'afsc_name'],
['field_name' => '会员电话', 'field_value' => 'afsc_phone'],
['field_name' => '车主姓名', 'field_value' => 'afsc_carowner_name'],
['field_name' => '车主电话', 'field_value' => 'afsc_carowner_phone'],
['field_name' => '车牌号', 'field_value' => 'afsc_car_num'],
['field_name' => '车架号', 'field_value' => 'afsc_car_vin'],
['field_name' => '品牌车系', 'field_value' => 'afsc_car_brand_series'],
['field_name' => '售后状态', 'field_value' => 'state_name'],
['field_name' => '创建人', 'field_value' => 'create_name'],
['field_name' => '售后位置', 'field_value' => 'afsl_parts'],
['field_name' => '指派技师', 'field_value' => 'return_adm_data'],
],
'WashViolation' => [//罚单列表
['field_name' => '订单单号', 'field_value' => 'viti_order_number'],
['field_name' => '处罚原因', 'field_value' => 'viti_reason'],
['field_name' => '处罚信息', 'field_value' => 'vtde_data'],
['field_name' => '创建人', 'field_value' => 'viti_create_name'],
['field_name' => '创建时间', 'field_value' => 'viti_create_time'],
['field_name' => '驳回原因', 'field_value' => 'viti_reject_reason'],
['field_name' => '状态', 'field_value' => 'viti_state'],
],
];
return $filed[$param];
}
}
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}
<?php
namespace App\Factory;
use BlueCity\Core\Inc\ServiceInc;
use App\Repository\Order\ApplyOrder;
use App\Repository\Order\HelpOrder;
use App\Repository\Order\PaintOrder;
use App\Repository\Order\PowderOrder;
use App\Repository\Order\WearingOrder;
class OrderFactory
{
public static function make($orderType)
{
if ($orderType == ServiceInc::SERVICE_POWDER) {
return new PowderOrder();
}
if ($orderType == ServiceInc::SERVICE_WEARING) {
return new WearingOrder();
}
if ($orderType == ServiceInc::SERVICE_HELP) {
return new HelpOrder();
}
if ($orderType == ServiceInc::SERVICE_APPLY) {
return new ApplyOrder();
}
if ($orderType == ServiceInc::SERVICE_PAINT) {
return new PaintOrder();
}
return false;
}
}
<?php
function getRealIp ($request) {
$ipAddress = $request->ip();
// 如果使用了代理,尝试获取真实IP
if ($request->server('HTTP_X_FORWARDED_FOR')) {
$ipAddress = $request->server('HTTP_X_FORWARDED_FOR');
} elseif ($request->server('HTTP_CLIENT_IP')) {
$ipAddress = $request->server('HTTP_CLIENT_IP');
}
$ipArray = explode(',',$ipAddress);
return $ipArray[0];
}
function whereFunction($data,$type=1) {
$shop_superior_id = DB::table('shop')
->where('shop_id', $data['user_info']->adm_shop_id)
->value('shop_superior_id');
$bind_shop = DB::table('shop')
->where('shop_superior_id', $data['user_info']->adm_shop_id)
->select('shop_id')
->get()->toArray();
$bind_shop_id = [];
foreach ($bind_shop as $key => $value) {
$bind_shop_id[] = $value->shop_id;
}
if ($type == 1) {//按分店id查询
$res['string'] = $data['string'].'shop_id';
$res['shop_id'][] = $data['user_info']->adm_shop_id;
} elseif ($type == 2) {//总店id查询
$res['string'] = $data['string'].'shop_id';
$res['shop_id'][] = $shop_superior_id;
} elseif ($type == 3) {//总店及此分店
$res['string'] = $data['string'].'shop_id';
if ($shop_superior_id == 0) {//总店及所有分店
$res['shop_id'][] = $data['user_info']->adm_shop_id;
if ($bind_shop_id) {
foreach ($bind_shop_id as $key => $value) {
$res['shop_id'][] = $value;
}
}
} else {
$res['shop_id'][] = $data['user_info']->adm_shop_id;
$res['shop_id'][] = $shop_superior_id;
}
}
return $res;
}
function addMoudleNum ($user_info,$data) {
$adm_shop_leave = DB::table('admin_shop_role')
->where('adm_id', $user_info->adm_id)
->where('shop_id', $user_info->adm_shop_id)
->value('adm_shop_leave');
if ($adm_shop_leave == 1) {//店长
$find_most = DB::table('moudle_statistics')
->where('most_shop_id', $user_info->adm_shop_id)
->where('most_adm_id', $user_info->adm_id)
->where('most_moudle_id', $data['most_moudle_id'])
->first();
if ($find_most) {
$add_res = DB::table('moudle_statistics')
->where('most_id', $find_most->most_id)
->increment('most_nums');
}
}
}
function shopFoldSize($shop_id) {
$imagePath = storage_path() .'/app/public/image/'.$shop_id;
$videoPath = storage_path() .'/app/public/video/'.$shop_id;
$imageSize = 0;
if (file_exists($imagePath)) {
$imageSize = getFolderSize($imagePath);
}
$videoSize = 0;
if (file_exists($videoPath)) {
$videoSize = getFolderSize($videoPath);
}
$all_size = $imageSize + $videoSize;
$roundedValue = ceil($all_size/1073741824 * 100) / 100;
$formattedValue = number_format($roundedValue, 2);
// $Gsize = round($all_size/1073741824,4);
return $formattedValue;
}
function getFolderSize($folderPath) {
$output = shell_exec('du -sb ' . $folderPath);
preg_match('/^(\d+)/', $output, $matches);
if (isset($matches[1])) {
$sizeInBytes = (int)$matches[1];
} else {
$sizeInBytes= 0;
}
return $sizeInBytes;
}
/**
* [addNewLog 添加操作日志]
* @param [type] $user_info [用户信息]
* @param [type] $oplo_ip [操作ip]
* @param [type] $oplo_module [操作模块]
* @param [type] $oplo_action [操作功能]
* @param [type] $oplo_content [操作内容]
*/
function addNewLog(
$user_info,
$data
) {
$user_info = json_decode(json_encode($user_info, true), true);
$add_data = [
'oplo_cid'=>$user_info['adm_cid'],
'oplo_shop_id'=>$user_info['adm_shop_id'],
'oplo_adm_id'=>$user_info['adm_id'],
'oplo_adm_name'=>$user_info['adm_name'],
'oplo_module'=>$data['oplo_module'],
'oplo_action'=>$data['oplo_action'],
'oplo_content'=>$data['oplo_content'],
'oplo_ip'=>$data['oplo_ip'],
'order_number'=>$data['order_number'],
'work_number'=>$data['work_number'],
'data_source'=>$data['data_source'],//操作来源 1 PC 2 小程序
];
return DB::table('operation_log')->insert($add_data);
}
/**
* 是否发送短信
* @authors ldj
* @email 909490343@qq.com
* @date 2023-10-27
* @param [type] $user_info [description]
* @param [type] $type [description]
* @return boolean [description]
*/
function isSend($user_info,$type)
{
$find_msg_config = DB::table('msg_config')
->where('msco_shop_id', $user_info->adm_shop_id)
->first();
if (!$find_msg_config) {
return false;
}
if ($find_msg_config->msco_is_send == 2) {
return false;
}
$msco_send_detail = explode(',',$find_msg_config->msco_send_detail);
if (!in_array($type,$msco_send_detail)) {
return false;
}
return true;
}
/**
* [uploadBase64Img 上传base64图片]
* @param [type] $stream [base64数据]
* @return [type] [上传成功返回图片路径,失败返回false]
*/
function uploadBase64Img($stream)
{
if (stristr($stream, 'data:image')) {
$stream = $stream;
} else {
$stream = "data:image/png;base64," . $stream;
}
//获取扩展名和文件名
if (preg_match('/(?<=\/)[^\/]+(?=\;)/', $stream, $pregR)) {
$streamFileType = '.' . $pregR[0];
}
$streamFileRand = time() . rand(11111, 99999); //产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
// $pathName = "/public/storage/image/" ;
$pathName = storage_path() . "/app/public/image/"; //获取上传图片路径
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName, 0775, true);
chmod($pathName, 0775);
}
$streamFilename = $pathName . $streamFileRand . $streamFileType; //上传到服务器图片路径
//处理base64文本,用正则把第一个base64,之前的部分砍掉
preg_match('/(?<=base64,)[\S|\s]+/', $stream, $streamForW);
if (file_put_contents($streamFilename, base64_decode($streamForW[0])) === false) {
return false;
} else {
// 返回路径
$filePath = "storage/image/" . $streamFileRand . $streamFileType;
return $filePath;
}
}
/**
* [uploadBase64ImgFolder 上传base64图片]
* @param [type] $shop_id [总店id]
* @param [type] $stream [base64数据]
* @param integer $type [类型1压缩图片2不压缩图片]
* @return [type] [description]
*/
function uploadBase64ImgFolder($shop_id, $stream, $type=1)
{
if (stristr($stream, 'data:image')) {
$stream = $stream;
} else {
$stream = "data:image/png;base64," . $stream;
}
$free = '';
if (isset($request['ord_order_number']) && !empty($request['ord_order_number'])) {
$find_order = DB::table('order')
->where('ord_order_number', $request['ord_order_number'])
->first();
if ($find_order && $find_order->ord_source == 5) {
$free = 'free';
}
}
if (empty($free)) {
// $shop_use_space = shopFoldSize($request['shop_id']);
// $find_shop = DB::table('shop')
// ->where('shop_id', $request['shop_id'])
// ->select('shop_free_space', 'shop_toll_space', 'shop_superior_id')
// ->first();
// $space = $find_shop->shop_free_space + $find_shop->shop_toll_space;
// if ($shop_use_space >= $space) {
// if ($find_shop->shop_superior_id) {//分店
// return response()->json(['code'=>501, 'msg'=>'空间不足,请联系总店购买空间后上传', 'data'=>'']);
// } else {//总店
// return response()->json(['code'=>502, 'msg'=>'空间不足,请购买空间后上传', 'data'=>'']);
// }
// }
}
//获取扩展名和文件名
if (preg_match('/(?<=\/)[^\/]+(?=\;)/', $stream, $ext)) {
$stream_file_type = '.' . $ext[0];
}
$stream_file_rand = time() . rand(11, 99) .rand(111, 999); //产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
$folder = $shop_id.date('/Y/m/d/');
$path_name = storage_path() . '/app/public/'.$free.'image/'.$folder; //获取上传图片路径
// 创建文件夹
if (!file_exists($path_name)) {
mkdir($path_name, 0775, true);
chmod($path_name, 0775);
}
$stream_file_name = $path_name . $stream_file_rand . $stream_file_type; //上传到服务器图片路径
//处理base64文本,用正则把第一个base64,之前的部分砍掉
preg_match('/(?<=base64,)[\S|\s]+/', $stream, $stream_base);
if (file_put_contents($stream_file_name, base64_decode($stream_base[0])) === false) {
return false;
} else {
if ($type == 1) {
// 压缩图片
$new_stream_file_name = $path_name .'2'.$stream_file_rand . $stream_file_type; //上传到服务器图片路径
imageCompress($stream_file_name, 1, $new_stream_file_name);
// 删除原来的图片
deleteImage([$stream_file_name]);
$stream_file_rand = '2'.$stream_file_rand;
}
// 读取图片
// 图片路径 http://mk.bluearp.com/storage/image/1/2020/12/02/159429003777298.png
// 返回路径 storage/image/1/2020/12/02/159429003777298.png
$file_path = 'storage/'.$free.'image/'.$folder. $stream_file_rand . $stream_file_type;
return $file_path;
}
}
/**
* [deleteImage 删除图片]
* @param [type] $image_path [图片路径,数组]
* @return [type] [description]
*/
function deleteImage($image_path)
{
if (empty($image_path)) {
return true;
}
try {
foreach ($image_path as $key => $value) {
unlink($value);//删除图片
}
} catch (Exception $e) {
}
return true;
}
/**
* [imageCompress 压缩图片]
* @param [type] $src [原来图片路径]
* @param [type] $percent [压缩比例]
* @param [type] $new_stream_file_name [压缩图片路径]
* @return [type] [description]
*/
function imageCompress($src, $percent, $new_stream_file_name)
{
// 打开图片
list($width, $height, $type, $attr) = getimagesize($src);
$imageinfo = [
'width'=>$width,
'height'=>$height,
'type'=>image_type_to_extension($type, false),
'attr'=>$attr,
];
$fun = 'imagecreatefrom'.$imageinfo['type'];
$image = $fun($src);
// 操作图片
$new_width = $imageinfo['width'] * $percent;
$new_height = $imageinfo['height'] * $percent;
$image_thump = imagecreatetruecolor($new_width, $new_height);
// 将原图复制带图片载体上面,并且按照一定比例压缩,极大的保持了清晰度
imagecopyresampled($image_thump, $image,0,0,0,0, $new_width, $new_height, $imageinfo['width'], $imageinfo['height']);
imagedestroy($image);
$image = $image_thump;
// 保存图片
$dst_img_name = $new_stream_file_name;
$allow_imgs = ['.jpg', '.jpeg', '.png', '.bmp', '.wbmp', '.gif'];//如果目标图片名有后缀就用目标图片扩展名 后缀,如果没有,则用源图的扩展名
$dst_ext = strrchr($dst_img_name, '.');
$sourse_ext = strrchr($src, '.');
if (!empty($dst_ext)) {
$dst_ext =strtolower($dst_ext);
}
if(!empty($sourse_ext)) {
$sourse_ext = strtolower($sourse_ext);
}
// 有指定目标名扩展名
if (!empty($dst_ext) && in_array($dst_ext, $allow_imgs)) {
$dst_name = $dst_img_name;
}elseif (!empty($sourse_ext) && in_array($sourse_ext, $allow_imgs)) {
$dst_name = $dst_img_name.$sourse_ext;
}else{
$dst_name = $dst_img_name.$imageinfo['type'];
}
$funcs = 'image'.$imageinfo['type'];
$funcs($image, $dst_name);
}
// 日志记录,记录操作数据
function logRecord($data, $file_name = 'log', $type = 1)
{
// $file_path = "./Uploads/".$file_name.".txt";
$file_path = storage_path() . "/logs/" . $file_name . ".txt";
$myfile = fopen($file_path, "a");
if ($type == 1) {
$txt = json_encode($data) . "\r\n\r\n";
}else{
$txt = json_encode($data, JSON_UNESCAPED_UNICODE) . "\r\n\r\n";
}
fwrite($myfile, $txt);
fclose($myfile);
}
// 日志记录,自定义文件夹,记录操作数据
function logFileRecord($data, $file_name = 'log', $type = 1)
{
// $file_path = "./Uploads/".$file_name.".txt";
$file_path = storage_path() . "/logs/" . $file_name . ".txt";
$pathName = substr($file_path, 0, strripos($file_path, '/') + 1);
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName, 0775, true);
chmod($pathName, 0775);
}
$myfile = fopen($file_path, "a");
if ($type == 1) {
$txt = json_encode($data) . "\r\n\r\n";
}else{
$txt = json_encode($data, JSON_UNESCAPED_UNICODE) . "\r\n\r\n";
}
fwrite($myfile, $txt);
fclose($myfile);
}
/**
* [getListButton 获取当前列表下按钮]
* @param [type] $api_token [用户token]
* @param [type] $pri_id [当前列表权限id]
* @return [type] [description]
*/
function getListButton($api_token, $pri_id)
{
$role_info = DB::table('login_temporary')
->where('api_token', '=', $api_token)
->select('role_auth')
->first();
$role_auth = json_decode($role_info->role_auth, true);
// 获取到当前列表下的按钮
foreach ($role_auth as $key => $value) {
if ($value['pri_fid'] == $pri_id && $value['pri_show'] == 1) {
$list_button[] = $value;
}
}
if (empty($list_button)) {
return false;
}
return $list_button;
}
/**
* [getListButton 小程序获取当前列表下按钮]
* @param [type] $api_token [用户token]
* @param [type] $pri_id [当前列表权限id]
* @return [type] [description]
*/
function getAppletListButton($api_token, $pri_id)
{
$role_info = DB::table('login_wechat_applet')
->where('api_token', '=', $api_token)
->select('role_auth')
->first();
$role_auth = json_decode($role_info->role_auth, true);
// 获取到当前列表下的按钮
foreach ($role_auth as $key => $value) {
if ($value['pri_fid'] == $pri_id && $value['pri_show'] == 1 && $value['have_pri'] == 1) {
$list_button[] = $value;
$pri_sord[] = $value['pri_sord'];
$pri_ids[] = $value['pri_id'];
}
}
if (empty($list_button)) {
return false;
}
array_multisort($pri_sord, SORT_NUMERIC, SORT_DESC, $pri_ids, SORT_NUMERIC, SORT_DESC, $list_button);
return $list_button;
}
// 获取验证码接口
function sendSmsCode($mobile, $content)
{
// return 1;
//配置文件中的账号密码
$sms_account = config('apisystem.sms_account');
$username = $sms_account[0]['account'];
$pwd = $sms_account[0]['password'];
$password = md5($username . "" . md5($pwd));
$url = "http://www1.jc-chn.cn/smsSend.do?";
$param = http_build_query(
array(
'username' => $username,
'password' => $password,
'mobile' => $mobile,
// 'content'=>iconv("GB2312","UTF-8",$content)
'content' => $content
)
);
/*
短信发送返回的状态码,状态码大于0的算发送成功
1 提交成功
0 失败
-1 用户名或者密码不正确
-2 必填选项为空
-3 短信内容0个字节
-5 余额不够
-10 用户被禁用
-11 短信内容超过500字
-12 无扩展权限(ext 字段需填空)
-13 IP校验错误
-14 内容解析异常
-990 未知错误
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
// 小程序-用户消息新增
function addUserMessage($data)
{
$add_data['weus_id'] = $data['weus_id'];
$add_data['shop_id'] = $data['shop_id'];
$add_data['primary_id'] = $data['primary_id'];//单据的主键id
$add_data['primary_type'] = $data['primary_type'];//单据类型:1订单2工单3预约单4售后单
$add_data['adm_type'] = isset($data['adm_type']) ? $data['adm_type'] : 1;//1门店2合作商
$add_data['read_state'] = $data['read_state'];//阅读状态:1未读2已读
$add_data['title'] = $data['title'];//消息标题
$add_data['content'] = $data['content'];//操作内容
$add_data['create_adm_name'] = $data['create_adm_name'];//操作人姓名
$add_data['create_adm_id'] = $data['create_adm_id'];//操作人id
$add_data['create_time'] = date('Y-m-d H:i:s');
$add_data['update_time'] = date('Y-m-d H:i:s');
$add_data_res = DB::table('user_message')->insert($add_data);
if ($add_data_res) {
return ['code'=>200, 'msg'=>'新增消息成功', 'data'=>'新增消息成功'];
} else {
return ['code'=>500, 'msg'=>'新增消息失败', 'data'=>'新增消息失败'];
}
}
// 小程序-技师消息新增
function addAdminMessage($data)
{
$add_data['adm_id'] = $data['adm_id'];
$add_data['shop_id'] = $data['shop_id'];
$add_data['primary_id'] = $data['primary_id'];//单据的主键id
$add_data['primary_type'] = $data['primary_type'];//单据类型:1订单2工单3预约单4售后单
// $add_data['message_type'] = 1;
$add_data['message_type'] = $data['message_type'];
// $add_data['primary_wor_state'] = isset($data['primary_wor_state'])?$data['primary_wor_state']:'';
$add_data['title'] = $data['title'];//标题
$add_data['content'] = $data['content'];//操作内容
$add_data['read_state'] = $data['read_state'];//阅读状态:1未读2已读
$add_data['create_adm_name'] = $data['create_adm_name'];//操作人姓名
$add_data['create_adm_id'] = $data['create_adm_id'];//操作人id
$add_data['create_time'] = date('Y-m-d H:i:s');
$add_data['update_time'] = date('Y-m-d H:i:s');
$add_data_res = DB::table('admin_message')->insert($add_data);
if ($add_data_res) {
return ['code'=>200, 'msg'=>'新增消息成功', 'data'=>'新增消息成功'];
} else {
return ['code'=>500, 'msg'=>'新增消息失败', 'data'=>'新增消息失败'];
}
}
// APP推送消息
function pushMessage($audience, $notification, $type = 1)
{
$audience['tag'] = $audience['alias'];//推送标签
$data = [
// 'platform'=>'all',//推送到所有平台
// 'audience'=>'all', //针对于所有人
// 'audience'=>["alias"=>[ "张利峰"]], //针对于某一个人
// 'notification'=>['alert'=>'请注意:工单70176347917370即将到预约时间'],
'platform' => ['android', 'ios'], //指定特定推送平台
'audience' => $audience, //针对于某一个人
'notification' => [
"android" => [
'alert' => $notification,
// 自定义字段
"extras" => [
// APP提示音类型:1新工单2催单3售后催单4工单预约提醒5速电锁定6系统锁定7速电取消锁定8系统取消锁定9审核改单10速电撤销
"type" => $type
]
],
"ios" => [
'alert' => [
'title' => '',
'body' => $notification
],
"sound" => "sound.caf",
"extras" => [
"type" => $type
]
],
],
"options" => [
"apns_production" => config('apisystem.apns_production'), //apns_production 字段来设定推送环境。True 表示推送生产环境,False 表示要推送开发环境; 如果不指定则为推送生产环境;一次只能推送给一个环境。
]
];
$return_data = curlPost(json_encode($data));
return json_decode($return_data, true);
}
function curlPost($data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1); //请求方式为POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //绑定POST要发送的数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //TRUE 将curl_exec()获取的信息以字符串返回,而不是直接输出。
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Basic Mjk1ODk5N2VmMmJkNDdkMDZlMmIyYmQxOmQ2Y2YzNGZjNWJlM2FkN2M1YjhhYTJiZQ==',
));
curl_setopt($ch, CURLOPT_HEADER, 0); //返回response头部信息
curl_setopt($ch, CURLINFO_HEADER_OUT, true); //TRUE 时追踪句柄的请求字符串,从 PHP 5.1.3 开始可用。这个很关键,就是允许你查看请求header
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 关闭SSL验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // 关闭SSL验证
curl_setopt($ch, CURLOPT_URL, 'https://api.jpush.cn/v3/push');
$result = curl_exec($ch);
$err = curl_error($ch);
if ($err) {
return "错误:" . $err;
} else {
return $result;
}
}
/**
* [模拟post提交]
* @param [string] $url [base64数据]
* @param [array] $param 路径 存放哪一个文件夹下
* @return [bool] 成功返回true
*/
function doPost($param, $url, $type=1)
{
// 模拟提交数据函数
$post_data = ToUrlencode($param);
$post_data=urldecode(json_encode($post_data));
// logFileRecord($post_data, 'doPost', 2);
// Common::write_log($param, $type);
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$tmpInfo = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo 'Errno' . curl_error($curl);//捕抓异常
}
curl_close($curl); // 关闭CURL会话
return $tmpInfo; // 返回数据,json格式
}
/**
* [ConvertGDToBD 高德地图经纬度转百度地图经纬度]
* @param [type] $lat [纬度]
* @param [type] $lng [经度]
*/
function convertGDToBD($lat, $lng)
{
$x_pi = 3.14159265358979324 * 3000.0 / 180.0;
$x = $lng;
$y = $lat;
$z = sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi);
$theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi);
$lat = $z * sin($theta) + 0.006;
$lng = $z * cos($theta) + 0.0065;
return array('lat' => $lat, 'lng' => $lng);
}
/**
* 计算两组经纬度坐标 之间的距离
* params :lat1 纬度1; lng1 经度1; lat2 纬度2; lng2 经度2; len_type (1:km or 2:m);
* return m or km
*/
function getDistance($lat1, $lng1, $lat2, $lng2, $len_type = 1, $decimal = 2)
{
if(!defined('EARTH_RADIUS')){
define('EARTH_RADIUS', 6378.137); //地球半径,假设地球是规则的球体
}
if(!defined('PI')){
define('PI', 3.1415926535898);
}
$radLat1 = $lat1 * PI() / 180.0; //PI()圆周率
$radLat2 = $lat2 * PI() / 180.0;
$a = $radLat1 - $radLat2;
$b = ($lng1 * PI() / 180.0) - ($lng2 * PI() / 180.0);
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
$s = $s * EARTH_RADIUS;
$s = round($s * 1000);
if ($len_type == 1) {
$s = $s / 1000;
}
return $s;
}
/**
* 订单操作记录信息
* @param $user_info string 用户信息
* @param $ord_id int 订单id
* @param $wor_id int 工单id
* @param $content string 操作内容
* @return json
*/
function orderLog($user_info, $ord_id, $wor_id, $content)
{
$data['orlo_cid'] = $user_info->adm_cid; //企业id
$data['orlo_superior_shop_id'] = $user_info->shop_superior_id; //总店id
$data['orlo_shop_id'] = $user_info->adm_shop_id; //所属门店id
$data['orlo_ord_id'] = $ord_id; //订单id
$data['orlo_wor_id'] = $wor_id; //工单id
$data['orlo_content'] = $content; //操作内容
$data['orlo_create_adm_name'] = $user_info->adm_name; //操作人姓名
$data['orlo_create_adm_id'] = $user_info->adm_id; //操作人id
$data['orlo_time'] = date('Y-m-d H:i:s'); //操做时间
return DB::table('order_log')->insert($data);
}
/**
* 商品操作记录信息
* @param $user_info string 用户信息
* @param $pait_id int 商品id
* @param $content string 操作内容
* @param $remark string 备注
* @return json
*/
function paitLog($user_info, $pait_id, $content, $remark)
{
$data['palo_cid'] = $user_info->adm_cid; //企业id
$data['palo_shop_id'] = $user_info->adm_shop_id; //所属门店id
$data['palo_pait_id'] = $pait_id; //商品id
$data['palo_content'] = $content; //操作内容
$data['palo_remark'] = $remark; //备注
$data['palo_create_name'] = $user_info->adm_name; //操作人姓名
$data['palo_create_id'] = $user_info->adm_id; //操作人id
$data['palo_create_time'] = date('Y-m-d H:i:s'); //操做时间
return DB::table('pait_log')->insert($data);
}
/**
* 单据类型操作记录信息
* @param $user_info string 用户信息
* @param $primary_id int 单据主键id
* @param $type int 单据类型:1预约单2售后单
* @param $content string 操作内容
* @param $ord_id int 订单id
* @param $wor_id int 工单id
* @return json
*/
function orderLogType($user_info, $primary_id=0, $type=0, $content, $ord_id=0, $wor_id=0)
{
$user_info = (array) $user_info;
$data['orlo_cid'] = $user_info['adm_cid']; //企业id
$data['orlo_superior_shop_id'] = $user_info['shop_superior_id']; //总店id
$data['orlo_shop_id'] = $user_info['adm_shop_id']; //所属门店id
$data['orlo_ord_id'] = $ord_id; //订单id
$data['orlo_wor_id'] = $wor_id; //工单id
$data['orlo_primary_id'] = $primary_id; //单据主键id
$data['orlo_primary_type'] = $type; //单据类型:1预约单2售后单
$data['orlo_content'] = $content; //操作内容
$data['orlo_create_adm_name'] = $user_info['adm_name']; //操作人姓名
$data['orlo_create_adm_id'] = $user_info['adm_id']; //操作人id
$data['orlo_time'] = date('Y-m-d H:i:s'); //操作时间
return DB::table('order_log')->insert($data);
}
/**
* 速电操作订单记录信息
* @param $user_info string 用户信息
* @param $ord_id int 订单id
* @param $wor_id int 工单id
* @param $content string 操作内容
* @return json
*/
function sdOrderLog($ord_data, $ord_id, $wor_id, $content)
{
$data['orlo_cid'] = $ord_data->ord_cid; //企业id
$data['orlo_superior_shop_id'] = $ord_data->ord_superior_shop_id; //总店id
$data['orlo_shop_id'] = $ord_data->ord_shop_id; //所属门店id
$data['orlo_ord_id'] = $ord_id; //订单id
$data['orlo_wor_id'] = $wor_id; //工单id
$data['orlo_content'] = $content; //操作内容
$data['orlo_create_adm_name'] = '速电'; //操作人姓名
$data['orlo_create_adm_id'] = 0; //操作人id
$data['orlo_time'] = date('Y-m-d H:i:s'); //操做时间
return DB::table('order_log')->insert($data);
}
// 阿拉伯数字金额转中文大写金额
function num_to_rmb($num)
{
$c1 = "零壹贰叁肆伍陆柒捌玖";
$c2 = "分角元拾佰仟万拾佰仟亿";
//精确到分后面就不要了,所以只留两个小数位
$num = round($num, 2);
//将数字转化为整数
$num = $num * 100;
if (strlen($num) > 10) {
return "金额太大,请检查";
}
$i = 0;
$c = "";
while (1) {
if ($i == 0) {
// 获取最后一位数字
$n = substr($num, strlen($num) - 1, 1);
} else {
$n = $num % 10;
} //每次将最后一位数字转换为中文
$p1 = substr($c1, 3 * $n, 3);
$p2 = substr($c2, 3 * $i, 3);
if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
$c = $p1 . $p2 . $c;
} else {
$c = $p1 . $c;
}
$i = $i + 1;
//去掉数字最后一位了
$num = $num / 10;
$num = (int) $num;
//结束循环
if ($num == 0) {
break;
}
}
$j = 0;
$slen = strlen($c);
while ($j <= $slen) {
//utf8一个汉字相当3个字符
$m = substr($c, $j, 6);
//处理数字中很多0的情况,每次循环去掉一个汉字“零”
if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
$left = substr($c, 0, $j);
$right = substr($c, $j + 3);
$c = $left . $right;
$j = $j - 3;
$slen = $slen - 3;
}
$j = $j + 3;
}
if (substr($c, strlen($c) - 3, 3) == '零') {
$c = substr($c, 0, strlen($c) - 3);
}
if (empty($c)) {
return "零元整";
} else {
return $c . "整";
}
}
// 将汉字转换为拼音和得到词语首字母
// function getfirstchar($s0)
// {
// $fchar = ord($s0{
// 0});
// if ($fchar >= ord("A") and $fchar <= ord("z")) {
// return strtoupper($s0{
// 0});
// }
// $s1 = @iconv("UTF-8", "gb2312", $s0);
// $s2 = @iconv("gb2312", "UTF-8", $s1);
// if ($s2 == $s0) {
// $s = $s1;
// } else {
// $s = $s0;
// }
// $asc = ord($s{
// 0}) * 256 + ord($s{
// 1}) - 65536;
// if ($asc >= -20319 and $asc <= -20284) {
// return "A";
// }
// if ($asc >= -20283 and $asc <= -19776) {
// return "B";
// }
// if ($asc >= -19775 and $asc <= -19219) {
// return "C";
// }
// if ($asc >= -19218 and $asc <= -18711) {
// return "D";
// }
// if ($asc >= -18710 and $asc <= -18527) {
// return "E";
// }
// if ($asc >= -18526 and $asc <= -18240) {
// return "F";
// }
// if ($asc >= -18239 and $asc <= -17923) {
// return "G";
// }
// if ($asc >= -17922 and $asc <= -17418) {
// return 'H';
// }
// if ($asc >= -17922 and $asc <= -17418) {
// return "I";
// }
// if ($asc >= -17417 and $asc <= -16475) {
// return "J";
// }
// if ($asc >= -16474 and $asc <= -16213) {
// return "K";
// }
// if ($asc >= -16212 and $asc <= -15641) {
// return "L";
// }
// if ($asc >= -15640 and $asc <= -15166) {
// return "M";
// }
// if ($asc >= -15165 and $asc <= -14923) {
// return "N";
// }
// if ($asc >= -14922 and $asc <= -14915) {
// return "O";
// }
// if ($asc >= -14914 and $asc <= -14631) {
// return "P";
// }
// if ($asc >= -14630 and $asc <= -14150) {
// return "Q";
// }
// if ($asc >= -14149 and $asc <= -14091) {
// return "R";
// }
// if ($asc >= -14090 and $asc <= -13319) {
// return "S";
// }
// if ($asc >= -13318 and $asc <= -12839) {
// return "T";
// }
// if ($asc >= -12838 and $asc <= -12557) {
// return "W";
// }
// if ($asc >= -12556 and $asc <= -11848) {
// return "X";
// }
// if ($asc >= -11847 and $asc <= -11056) {
// return "Y";
// }
// if ($asc >= -11055 and $asc <= -10247) {
// return "Z";
// }
// return null;
// }
function pinyin1($zh)
{
$ret = "";
$s1 = iconv("UTF-8", "gb2312", $zh);
$s2 = iconv("gb2312", "UTF-8", $s1);
if ($s2 == $zh) {
$zh = $s1;
}
for ($i = 0; $i < strlen($zh); $i++) {
$s1 = substr($zh, $i, 1);
$p = ord($s1);
if ($p > 160) {
$s2 = substr($zh, $i++, 2);
$ret .= getfirstchar($s2);
} else {
$ret .= $s1;
}
}
return $ret;
}
/**
* 打印sql语句
* @return [string] [sql语句]
*/
function print_sql()
{
DB::listen(function ($query) {
$bindings = $query->bindings;
$sql = $query->sql;
foreach ($bindings as $replace) {
$value = is_numeric($replace) ? $replace : "'" . $replace . "'";
$sql = preg_replace('/\?/', $value, $sql, 1);
}
dump($sql);
die;
});
}
/**
* SQL语句日志记录
* @return [string] [sql语句]
*/
function sqlLog()
{
DB::listen(function ($query) {
$bindings = $query->bindings;
$sql = $query->sql;
foreach ($bindings as $replace) {
$value = is_numeric($replace) ? $replace : "'" . $replace . "'";
$sql = preg_replace('/\?/', $value, $sql, 1);
}
$path = storage_path() . "/logs/sqlLog/"; //日志路径
// 创建文件夹
if (!file_exists($path)) {
mkdir($path, 0775, true);
chmod($path, 0775);
}
// 将SQL语句存入日志文件
$file_path = storage_path() . "/logs/sqlLog/" . date('Y-m-d') . ".txt";
$myfile = fopen($file_path, "a");
$txt = date('Y-m-d H:i:s').' '.json_encode($sql) . "\r\n\r\n";
fwrite($myfile, $txt);
fclose($myfile);
});
}
/**
* [truncateFill 截取填充固定位数]
* @param [type] $number [不定长的数字]
* @param [type] $digit [要保留的固定位数]
* @return [type] [返回截取填充后的数据]
*/
function truncateFill($number, $digit)
{
return str_pad(substr($number, '-' . $digit), $digit, 0, STR_PAD_LEFT);
}
/**
* 将 去除所有空格换行符等其他符号
* @param [type] $data [description]
*/
function RemoveLineFeed($data)
{
if (is_array($data)) {
foreach ($data as $key => $val) {
$data[$key] = RemoveLineFeed($val);
}
return $data;
} else {
$data = str_replace(array("\r\n", "\r", "\n", "\t", " "), " ", $data);
$data = trim($data, " ");
return $data;
}
}
/**
* 记录错误日志
* @param [type] $data 内容
* @param string $path 路径
*/
function LogInfo($data, $path = "")
{
if ($path != "") {
$monolog = \Log::getMonolog();
$monolog->popHandler();
\Log::useDailyFiles(storage_path('logs/' . $path . '.log'));
}
\Log::info($data);
}
/**
* 将 null 替换为 ""
* @param [type] $data [description]
*/
function RemoveNull($data)
{
if (is_array($data)) {
foreach ($data as $key => $val) {
$data[$key] = RemoveNull($val);
}
return $data;
} else {
if ($data === null) {
return "";
} else {
return trim($data);
}
}
}
/**
* [simulationPost 模拟post提交数据函数]
* @param [type] $url [请求网址]
* @param array $param [参数]
* @return [type] [description]
*/
function simulationPost($url, array $param)
{
$post_data = toUrlencode($param);
$post_data = urldecode(json_encode($post_data));
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$tmpInfo = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo 'Errno' . curl_error($curl); //捕抓异常
}
curl_close($curl); // 关闭CURL会话
return $tmpInfo; // 返回数据,json格式
}
function toUrlencode($arr)
{
$temp = array();
if (is_array($arr)) {
foreach ($arr as $key => $row) {
$temp[$key] = $row;
if (is_array($temp[$key])) {
$temp[$key] = toUrlencode($temp[$key]);
} else {
$temp[$key] = urlencode($row);
}
}
} else {
$temp = $arr;
}
return $temp;
}
//判断工单状态
function stateSetting($state)
{
if (in_array($state, [1, 2, 3])) {
$state = 1;
} else {
switch ($state) {
case 4:
$state = 2;
break;
case 5:
$state = 3;
break;
case 6:
$state = 4;
break;
case 7:
$state = 5;
break;
case 8:
$state = 6;
break;
case 9:
$state = 7;
break;
case 10:
$state = 8;
break;
case 11:
$state = 9;
break;
case 12:
$state = 10;
break;
default:
$state = 0;
break;
}
}
return $state;
}
/**
* 订单售后操作记录信息
* @param $user_info string 用户信息
* @param $ord_id int 订单/工单/售后单id
* @param $type int 类型1订单2工单3售后单
* @param $content string 操作内容
* @return json
*/
function orderAfterLog($user_info, $ord_id, $type, $content)
{
$data['oral_cid'] = $user_info->adm_cid; //企业id
$data['oral_superior_shop_id'] = $user_info->shop_superior_id; //总店id
$data['oral_shop_id'] = $user_info->adm_shop_id; //所属门店id
$data['oral_ord_id'] = $ord_id; //订单id
$data['oral_type'] = $type; //工单id
$data['oral_content'] = $content; //操作内容
$data['oral_create_adm_name'] = $user_info->adm_name; //操作人姓名
$data['oral_create_adm_id'] = $user_info->adm_id; //操作人id
$data['oral_time'] = date('Y-m-d H:i:s'); //操做时间
return DB::table('order_after_log')->insert($data);
}
// 判断售后单状态
function stateAfterSetting($state)
{
if (in_array($state, [1])) {
$state = 1;
} else {
switch ($state) {
case 2:
$state = 2;
break;
case 3:
$state = 3;
break;
case 4:
$state = 1;
break;
case 5:
$state = 2;
break;
case 6:
$state = 3;
break;
case 7:
$state = 5;
break;
case 8:
$state = 6;
break;
case 9:
$state = 7;
break;
case 10:
$state = 8;
break;
case 11:
$state = 10;
break;
default:
$state = 0;
break;
}
}
return $state;
}
/**
* [addInformationHint 添加信息提示]
* @param [type] $user_info [用户信息]
* @param [type] $add_data [单号信息]
* @param [type] $type [单号类型:1订单]
*/
function addInformationHint($user_info, $add_data, $type)
{
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$inhi_data['inhi_cid'] = $user_info->adm_cid;
$inhi_data['inhi_shop_id'] = $user_info->adm_shop_id;
$inhi_data['inhi_shop_superior_id'] = $shop_id;
$inhi_data['inhi_adm_id'] = $user_info->adm_id;
$inhi_data['inhi_original_adm_id'] = $add_data['inhi_original_adm_id'];//原始单号创建人
$inhi_data['inhi_original_id'] = $add_data['inhi_original_id'];//原始单id
$inhi_data['inhi_original_number'] = $add_data['inhi_original_number'];//原始单号
$inhi_data['inhi_original_state'] = $add_data['inhi_original_state'];//原始单状态
$inhi_data['inhi_original_operation'] = $add_data['inhi_original_operation'];//操作
$inhi_data['inhi_operation_state'] = $add_data['inhi_operation_state'];//操作状态:1新订单
$inhi_data['inhi_type'] = $type;//单号类型:1订单2工单3速电网单
$res = DB::table('information_hint')->insert($inhi_data);
return $res;
}
/**
* 订单工单备注信息
* @param $user_info string 用户信息
* @param $ord_id int 订单id
* @param $wor_id int 工单id
* @param $content string 操作内容
* @param $module string 操作模块
* @return json
*/
function orderRemark($user_info, $ord_id, $wor_id, $content, $module = '')
{
$time = date('Y-m-d H:i:s');
$data['orre_cid'] = $user_info->adm_cid; //企业id
$data['orre_superior_shop_id'] = $user_info->shop_superior_id; //总店id
$data['orre_shop_id'] = $user_info->adm_shop_id; //所属门店id
$data['orre_ord_id'] = $ord_id; //订单id
$data['orre_wor_id'] = !empty($wor_id) ? $wor_id :0; //工单id
$data['orre_content'] = $content; //操作内容
$data['orre_create_adm_name'] = $user_info->adm_name; //操作人姓名
$data['orre_create_adm_id'] = $user_info->adm_id; //操作人id
$data['orre_time'] = $time; //操做时间
$data['orre_module'] = $module; //操作模块
if(!empty($ord_id)){
DB::table('order')
->where('ord_id',$ord_id)
->update(['ord_remark'=>$content,'ord_update_time'=>$time]);
}
if(!empty($wor_id)){
DB::table('work_order')
->where('wor_id',$wor_id)
->update(['wor_remark'=>$content,'wor_update_time'=>$time]);
}
return DB::table('order_remarks')->insert($data);
}
/**
* 订单工单备注信息
* @param $user_info string 用户信息
* @param $primary_id int 单据的主键id
* @param $primary_type int 单据类型:1预约单2售后单
* @param $content string 操作内容
* @param $module string 操作模块
* @param $ord_id int 订单id
* @param $wor_id int 工单id
* @return json
*/
function orderRemarkType($user_info, $primary_id, $primary_type, $content, $module = '', $ord_id=0, $wor_id=0)
{
$time = date('Y-m-d H:i:s');
$data['orre_cid'] = $user_info->adm_cid; //企业id
$data['orre_superior_shop_id'] = $user_info->shop_superior_id; //总店id
$data['orre_shop_id'] = $user_info->adm_shop_id; //所属门店id
$data['orre_primary_id'] = $primary_id; //单据的主键id
$data['orre_primary_type'] = $primary_type; //单据类型:1预约单2售后单
$data['orre_ord_id'] = $ord_id; //订单id
$data['orre_wor_id'] = $wor_id; //工单id
$data['orre_content'] = empty($content)?'':$content; //操作内容
$data['orre_create_adm_name'] = $user_info->adm_name; //操作人姓名
$data['orre_create_adm_id'] = $user_info->adm_id; //操作人id
$data['orre_time'] = $time; //操做时间
$data['orre_module'] = $module; //操作模块
if(!empty($ord_id)){
DB::table('order')
->where('ord_id',$ord_id)
->update(['ord_remark'=>$content,'ord_update_time'=>$time]);
}
if(!empty($wor_id)){
DB::table('work_order')
->where('wor_id',$wor_id)
->update(['wor_remark'=>$content,'wor_update_time'=>$time]);
}
return DB::table('order_remarks')->insert($data);
}
/**
* [substituteCharacter 替换字符-中文字符]
* @param [type] $character [字符]
* @return [type] [description]
*/
function substituteCharacter($character)
{
// 获取字符串的长度
$length = mb_strlen($character, 'utf-8');
// 获取第一个字符
$mb_first = mb_substr($character, 0, 1, 'utf-8');
if($length >= 3){
// 获取最后一个字符
$mb_last = mb_substr($character, $length-1, 1,'utf-8');
} else {
$mb_last = '*';
}
return $mb_first.'****'.$mb_last;
}
/**
* [ 替换字符-中文字符]
* @param [type] ord_type [int]
* @return [type] [description]
*/
function ordType($ord_type)
{
switch ($ord_type) {
case 1:
$ord_type = '服务单';
break;
case 2:
$ord_type = '销售单';
break;
case 3:
$ord_type = '换货单';
break;
case 4:
$ord_type = '退货单';
break;
case 5:
$ord_type = '发货单';
break;
case 6:
$ord_type = '结清单';
break;
case 7:
$ord_type = '救援单';
break;
default:
$ord_type = '未知';
break;
}
return $ord_type;
}
/**
* [dateSomeMonthsLater 几个月后的时间]
* @param [type] $now_time [日期,格式年月日 时分秒]
* @param [type] $some_months [几个月]
* @return [type] [description]
*/
function dateSomeMonthsLater($now_time, $some_months)
{
$end_time = date('Y-m-d H', strtotime( '+'.$some_months.' months', strtotime($now_time)));
return $end_time;
}
// function isCarLicense($license)
// {
// if (empty($license)) {
// return false;
// }
// // 匹配民用车牌和使馆车牌
// // 1,第一位为汉字省份缩写
// // 2,第二位为大写字母城市编码
// // 3,后面是5位仅含字母和数字的组合
// // $regular = "/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新使]{1}[A-Z]{2}[0-9a-zA-Z]{6}$/u";
// $regular = "/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新使]{1}[0-9a-zA-Z]{5,7}$/u";
// $result = preg_match($regular, $license, $match);
// if ($result) {
// return true;
// }
// return false;
// }
function isCarLicense($license)
{
if (empty($license)) {
return false;
}
// 匹配民用车牌和使馆车牌
// 1,第一位为汉字省份缩写
// 2,第二位为大写字母城市编码
// 3,后面是5位仅含字母和数字的组合
$regular = "/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新使]{1}[A-Z]{1}[0-9a-zA-Z]{5}$/u";
$result = preg_match($regular, $license, $match);
if ($result) {
return true;
}
// 匹配特种车牌(挂,警,学,领,港,澳)
$regular = '/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[A-Z]{1}[0-9a-zA-Z]{4}[挂警学领港澳]{1}$/u';
$result = preg_match($regular, $license, $match);
if ($result) {
return true;
}
// 匹配武警车牌
$regular = '/^WJ[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]?[0-9a-zA-Z]{5}$/ui';
$result = preg_match($regular, $license, $match);
if ($result) {
return true;
}
// 匹配军牌
$regular = "/[A-Z]{2}[0-9]{5}$/";
$result = preg_match($regular, $license, $match);
if ($result) {
return true;
}
// 匹配新能源车辆6位车牌
# $regular = "/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[A-Z]{1}[DF]{1}[0-9a-zA-Z]{5}$/u";// 小型新能源车
$regular = "/[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[0-9a-zA-Z挂学警港澳]{5,7}$/u";// 小型新能源车
$result = preg_match($regular, $license, $match);
if ($result) {
return true;
}
$regular = "/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[A-Z]{1}[0-9a-zA-Z]{5}[DF]{1}$/u";//大型新能源车
$result = preg_match($regular, $license, $match);
if ($result) {
return true;
}
return false;
}
function addHistory($data)
{
$add_data['wohi_primary_id'] = $data['wohi_primary_id'];
$add_data['wohi_state_name'] = $data['wohi_state_name'];
$add_data['wohi_state'] = $data['wohi_state'];
$add_data['wohi_type'] = $data['wohi_type'];////1订单2工单
$add_data['wohi_create_time'] = date('Y-m-d H:i:s');
$add_res = DB::table('work_order_history')->insert($add_data);
return $add_res;
}
function computeTime($begin_time , $end_time = '' ){
if($begin_time < $end_time){
$starttime = $begin_time;
$endtime = $end_time;
}else{
$starttime = $end_time;
$endtime = $begin_time;
}
$starttime = strtotime($starttime);
$endtime = strtotime($endtime);
//计算天数
$timediff = $endtime-$starttime;
$days = intval($timediff/86400);
//计算小时数
$remain = $timediff%86400;
$hours = intval($remain/3600);
//计算分钟数
$remain = $remain%3600;
$mins = intval($remain/60);
//计算秒数
$secs = $remain%60;
$res = array("day" => $days,"hour" => $hours,"min" => $mins,"sec" => $secs);
return $days.'天'.$hours.'小时'.$mins.'分钟';
}
function addHttpurl($url) {
if (substr($url, 0, 4) != 'http') {
$url = config('apisystem.server_name_https').'/'.$url;
}
return $url;
}
// 等比例复制图片
function copyImage($src, $newname)
{
ini_set("memory_limit","-1");
$filename=str_replace("images","image",$newname);
$size = getimagesize($src);
if (!$size){
return false;
}
list($src_w, $src_h, $src_type) = $size;
$src_mime = $size['mime'];
switch ($src_type) {
case 1 :
$img_type = 'gif';
break;
case 2 :
$img_type = 'jpeg';
break;
case 3 :
$img_type = 'png';
break;
case 15 :
$img_type = 'wbmp';
break;
default :
return false;
}
//等比例缩放
if (!isset($width)){
$width = $src_w;
}
if (!isset($height)){
$height = $src_h;
}
//根据上传的文件的类型来调用不同函数
$imagecreatefunc = 'imagecreatefrom' . $img_type;
$src_img = $imagecreatefunc($src);
//新建一个真彩色图像
$dest_img = imagecreatetruecolor($width, $height);
//重采样拷贝部分图像并调整大小
/**
imagecopyresampled() 将一幅图像中的一块正方形区域拷贝到另一个图像中,平滑地插入像素值,
因此,尤其是,减小了图像的大小而仍然保持了极大的清晰度。
如果源和目标的宽度和高度不同,则会进行相应的图像收缩和拉伸。坐标指的是左上角。
本函数可用来在同一幅图内部拷贝(如果 dst_image 和 src_image 相同的话)区域,但如果区域交迭的话则结果不可预知。
*/
imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
$imagefunc = 'image' . $img_type;
if ($filename) {
$imagefunc($dest_img, $filename);
} else {
header('Content-Type: ' . $src_mime);
$imagefunc($dest_img);
}
//销毁文件资源
imagedestroy($src_img);
imagedestroy($dest_img);
return true;
/**
* @name 修改图片大小 按照指定大小压缩
* @param $filename:文件名
* @param$tmpname:文件路径,如上传中的临时目录
* @param $percent 为缩小比例
* @param $img
* @param $size
* @param $tmpname
* @param $xmax
* @param $ymax
* @param $type 是否删除原图片1删除2不删除
* @author du
* @date 2023/1/2
* @Time: 9:07
*/
function resizeImage($img,$size,$tmpname,$type = 1){
//获取图片大小
$s = @filesize($img); //echo $s; exit;
$img_size = ceil($s/ 1000) . "k"; //获取文件大小
if($img_size>$size){
$percent = 0.7;
list($width, $height) = getimagesize($img);
$ii = getimagesize($img);
$iimagen = explode('/', end($ii))[1];
$new_width = $width * $percent;
$new_height = $height * $percent;
$image_p = @imagecreatetruecolor($new_width, $new_height);
// $image = imagecreatefromjpeg($img);
$image = getImgN($img,$iimagen);
//print_r($image);
@imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$new_img = $tmpname.uniqid().'.'.$iimagen;
@imagejpeg($image_p,$new_img); //输出保存图片
if(file_exists($new_img)){
if($type == 1) {
unlink($img);
}
return resizeImage($new_img,$size,$tmpname);
}else{
\App\Services\CommonService::addLog('新图片不存在', $new_img, '1111111111111','新图片不存在');
}
}else{
return $img;
}
}
//获取图片后缀名
function getImgN($filename,$iimagen){
switch($iimagen){
case "png":
$img_r = imagecreatefrompng($filename);
break;
case "jpg":
$img_r = imagecreatefromjpeg($filename);
break;
case "jpeg":
$img_r = imagecreatefromjpeg($filename);
break;
case "gif":
$img_r = imagecreatefromgif($filename);
break;
}
return $img_r;
}
}
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class AESController extends Controller
{
private $hex_iv = '00000000000000000000000000000000';
private $key = '397e2eb61307109f6e68006ebcb62f98';
function __construct($key) {
$this->key = $key;
$this->key = hash('sha256', $this->key, true);
}
/*
* 字符串加密 不写入文件
*/
public function encrypt($input)
{
$data = openssl_encrypt($input, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->hexToStr($this->hex_iv));
$data = base64_encode($data);
return $data;
}
/*
* aes 给PHP文件加密
* 写入设置文件
*/
public function filecrypt($filename)
{
$type=strtolower(substr(strrchr($filename,'.'),1));
if ('php' == $type && is_file($filename) && is_writable($filename)) {
$contents = file_get_contents($filename);
$contents = php_strip_whitespace($filename);
$data = openssl_encrypt($contents, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->hexToStr($this->hex_iv));
$data = base64_encode($data);
return file_put_contents($filename, $data);
}
return false;
}
/*
* 字符串解密
*/
public function decrypt($input)
{
$decrypted = openssl_decrypt(base64_decode($input), 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->hexToStr($this->hex_iv));
return $decrypted;
}
/*
For PKCS7 padding
*/
private function addpadding($string, $blocksize = 16)
{
$len = strlen($string);
$pad = $blocksize - ($len % $blocksize);
$string .= str_repeat(chr($pad), $pad);
return $string;
}
private function strippadding($string)
{
$slast = ord(substr($string, -1));
$slastc = chr($slast);
$pcheck = substr($string, -$slast);
if (preg_match("/$slastc{" . $slast . "}/", $string)) {
$string = substr($string, 0, strlen($string) - $slast);
return $string;
} else {
return false;
}
}
private function hexToStr($hex)
{
$string='';
for ($i = 0; $i < strlen($hex)-1; $i += 2) {
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyAccountSubjectController;
use App\Http\Controllers\Api\YongYou\YongYouController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
// 账户管理-科目列表-用友系统
class AccountSubjectController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountSubjectController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('account_subject as acsu')
->leftJoin('account_subject_sublist as acss', 'acss.acss_acsu_id', '=', 'acsu.acsu_id')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('acsu_shop_superior_id', $shop_id)
->where('subjlev', 1)
->where(function($query) use($search_data) {
if (!empty($search_data['subjcode'])) {
$query->where('subjcode', 'like', '%'.$search_data['subjcode'].'%');
}
}) //科目编码
->where(function($query) use($search_data) {
if (!empty($search_data['subjname'])) {
$query->where('subjname', 'like', '%'.$search_data['subjname'].'%' );
}
}) //科目名称
->where(function($query) use($search_data) {
if (!empty($search_data['dispname'])) {
$query->where('dispname', 'like', '%'.$search_data['dispname'].'%' );
}
}) //显示名称
->where(function($query) use($search_data) {
if (!empty($search_data['engsubjname'])) {
$query->where('engsubjname', 'like', '%'.$search_data['engsubjname'].'%' );
}
}) //英文名称
->where(function($query) use($search_data) {
if (!empty($search_data['remcode'])) {
$query->where('remcode', 'like', '%'.$search_data['remcode'].'%' );
}
}) //助记码
->where(function($query) use($search_data) {
if (!empty($search_data['balanorient'])) {
$query->where('balanorient', $search_data['balanorient']);
}
}) //科目方向 1:借2:贷
->where(function($query) use($search_data) {
if (!empty($search_data['endflag'])) {
$query->where('endflag', $search_data['endflag']);
}
}) //是否末级:Y:是/N:否
->where(function($query) use($search_data) {
if (!empty($search_data['typeindex'])) {
$query->where('typeindex', $search_data['typeindex']);
}
}) //科目类型顺序号
->select('acsu_id', 'subjcode', 'subjname', 'dispname', 'engsubjname', 'remcode', 'subjlev', 'endflag',
'balanorient', 'sealflag', 'beginyear', 'beginperiod', 'acsu_bdin_id', 'typeindex')
->orderBy('subjcode', 'asc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
$list_items = $this->inquireChildren($user_info, $list_items, 1, []);
$suty_data = DB::table('subject_type')
->select('typeindex', 'subjtypename')
->get();
$data_info['suty_data'] = $suty_data;//科目类型数据
$bdin_data = DB::table('bdinfo')
->select('bdin_id', 'bdname')
->get();
$data_info['bdin_data'] = $bdin_data;//辅助核算项数据
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
/**
* [inquireChildren 搜索下级数据]
* @param [type] $user_info [用户信息]
* @param [type] $data [列表数据]
* @param integer $subjlev [科目级数]
* @return [type] [description]
*/
private function inquireChildren($user_info, $data, $subjlev = 1, $acsu_bdin_id)
{
$subjlev = $subjlev + 1;//科目级次
foreach ($data as $key => $value) {
if ($value->endflag == 'N') {
$children = DB::table('account_subject as acsu')
->leftJoin('account_subject_sublist as acss', 'acss.acss_acsu_id', '=', 'acsu.acsu_id')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('subjcode', 'like', $value->subjcode.'%' )
->where('subjlev', $subjlev)
->select('acsu_id', 'subjcode', 'subjname', 'dispname', 'engsubjname', 'remcode', 'subjlev', 'endflag',
'balanorient', 'sealflag', 'beginyear', 'beginperiod', 'acsu_bdin_id', 'typeindex')
->get();
// 递归查询下一级的数据
$data[$key]->children = $this->inquireChildren($user_info, $children, $subjlev, $acsu_bdin_id);
}
}
return $data;
}
// 详情
public function info(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountSubjectController;
$error_message = $verify_data->infoValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$search_data = $request->all();
$find_data = DB::table('account_subject as acsu')
->leftJoin('account_subject_sublist as acss', 'acss.acss_acsu_id', '=', 'acsu.acsu_id')
->where('acsu_id', $request['acsu_id'])
->select('acsu_id', 'subjcode', 'subjname', 'dispname', 'engsubjname', 'remcode', 'subjlev', 'endflag',
'balanorient', 'sealflag', 'beginyear', 'beginperiod', 'acsu_bdin_id', 'typeindex', 'acss_bdinfo',
'cashbankflag', 'currency', 'sumprint_level', 'incurflag', 'balanflag', 'accremove',
'outflag', 'bothorient', 'innersubj', 'unit')
->first();
// 获取科目类型顺序号
if (!empty($find_data->typeindex)) {
$suty_data = DB::table('subject_type')
->where('typeindex', $find_data->typeindex)
->select('typeindex', 'subjtypename')
->get();
$data_info['suty_data'] = $suty_data;//科目类型数据
}
$find_data->numberAccounting = empty($find_data->unit) ? 'N' : 'Y';//数量核算取值:Y:是/N:否;判断计量单位
$find_data->sealflag = empty($find_data->sealflag) ? 'N' : 'Y';//封存:Y:是/N:否
// 辅助核算项id
if ($find_data->acsu_bdin_id) {
$acsu_bdin_id = array_unique(explode(',', $find_data->acsu_bdin_id));
$bdin_data = DB::table('bdinfo')
->whereIn('bdin_id', $acsu_bdin_id)
->select('bdin_id', 'bdcode', 'bdname')
->get();
$data_info['bdin_data'] = $bdin_data;//辅助核算项数据
}
$data_info['data'] = $find_data;
if($data_info) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 新增
public function add(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountSubjectController;
$error_message = $verify_data->addValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 判断科目名称是否存在
$acsu_cid = DB::table('account_subject')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('subjname', $request['subjname'])
->value('acsu_cid');
if ($acsu_cid) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'科目名称已存在']);
}
$acsu_cid = DB::table('account_subject')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('subjcode', $request['subjcode'])
->value('acsu_cid');
if ($acsu_cid) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'科目编码已存在']);
}
DB::beginTransaction();
$add_data['acsu_cid'] = $user_info->adm_cid;//公司id
$add_data['acsu_shop_id'] = $user_info->adm_shop_id;//门店id
$add_data['acsu_shop_superior_id'] = $shop_id;//总店id
$add_data['acsu_adm_id'] = $user_info->adm_id;//创建人id
$add_data['pk_corp'] = '0001';//公司编码---后台查询
$add_data['subjcode'] = $request['subjcode'];//科目编码
$add_data['subjname'] = $request['subjname'];//科目名称
$add_data['dispname'] = $request['subjname'];//显示名称
$add_data['engsubjname'] = $request['engsubjname'] ? $request['engsubjname'] : '';//英文名称
$add_data['balanorient'] = $request['balanorient'];//余额方向 1:借2:贷
if ($request['sealflag'] == 'Y') {
$add_data['sealflag'] = date('Y-m-d');//封存标志:封存日期;数据库存的是日期,页面显示 Y N
}else{
$add_data['sealflag'] = '';//封存标志:封存日期;数据库存的是日期,页面显示 Y N
}
$add_data['incurflag'] = $request['incurflag'];//发生额方向控制取值:Y:是/N:否
$add_data['balanflag'] = $request['balanflag'];//余额方向控制取值:Y:是/N:否
$add_data['bothorient'] = $request['bothorient'];//帐簿余额双向显示取值:Y:是/N:否
$add_data['innersubj'] = $request['innersubj'];//内部交易科目取值:Y:是/N:否
$add_data['accremove'] = $request['accremove'];//是否核销科目取值:Y:是/N:否
$add_data['cashbankflag'] = $request['cashbankflag'];//现金银行科目 0:其他1:现金科目2:银行科目3:现金等价物
$add_data['unit'] = $request['unit'];//计量单位
$add_data['outflag'] = $request['outflag'];//表外科目取值:Y:是/N:否
$add_data['remcode'] = $request['remcode'];//助记码
$subjlev_arr = [4=>1,6=>2,8=>3,10=>4];//科目级次 4-2-2-2
$subjcode_strlen = strlen($request['subjcode']);//新增的科目编码的长度
// 判断是不是一级科目
if ($subjcode_strlen != 4) {
// 不是一级科目,将上一级的科目 末级标志取值 改为N:否
$superior_subjcode = substr($request['subjcode'], 0, -2);//上级科目编码
// 判断上级科目是否存在
$superior_acsu_id = DB::table('account_subject')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('subjcode', $superior_subjcode)
->value('acsu_id');
if (empty($superior_acsu_id)) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'上级科目不存在!']);
}
// 将上一级的科目 末级标志取值 改为N:否
$superior_res = DB::table('account_subject')
->where('acsu_id', $superior_acsu_id)
->update(['endflag'=>'N', 'acsu_update_time'=>date('Y-m-d H:i:s')]);
}else{
$superior_res = true;
}
$add_data['subjlev'] = $subjlev_arr[$subjcode_strlen];//科目级次
$add_data['endflag'] = 'Y';//末级标志取值:Y:是/N:否;这个是计算的,后台判断这个科目是否是末级
$add_data['innerinfonull'] = 'N';//内部交易信息是否必录取值:Y:是/N:否
$add_data['currency'] = $request['currency'];//科目默认币种,可以不选择,不选择就是null
$add_data['beginyear'] = '2020';//启用年度,年 2020 四位
$add_data['beginperiod'] = '06';//启用期间,月 06 两位
$add_data['stoped'] = 'N';//停用标志取值:Y:是/N:否
$add_data['createyear'] = '2020';//创建年度
$add_data['createperiod'] = '06';//创建月份
$add_data['sumprint_level'] = $request['sumprint_level'];//汇总打印级次 0末级 最大数量是科目级次数量
$add_data['pk_subjscheme'] = '0001F8100000000001T1';//科目方案
$add_data['pk_glorgbook'] = '0001F810000000000330';//会计主体账簿
$add_data['pk_create_glorgbook'] = '0001F810000000000330';//创建会计主体账簿
$dbin_id_arr = json_decode($request['bdin_id'], true);
if (!empty($dbin_id_arr)) {
if (empty($dbin_id_arr)) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'请选择辅助核算项']);
}
$acsu_bdin_id = array_column($dbin_id_arr, 'bdin_id');
$add_data['acsu_bdin_id'] = implode(',', $acsu_bdin_id);//辅助核算项id
$acsb_data['acss_bdinfo'] = $request['bdin_id'];//辅助核算项json数据
}else{
$add_data['acsu_bdin_id'] = '';
$acsb_data['acss_bdinfo'] = '';
}
$acsu_id = DB::table('account_subject')->insertGetId($add_data);
$acsb_data['acss_acsu_id'] = $acsu_id;
$acsb_data['typeindex'] = $request['typeindex'];//科目类型
$acsb_res = DB::table('account_subject_sublist')->insert($acsb_data);
// 科目类型名称
$add_data['subjtypename'] = DB::table('subject_type')
->where('typeindex',$request['typeindex'])
->value('subjtypename');
// 调用u8系统接口,将科目数据传到用友系统上
$yongyou = new YongYouController;
// 获取门店对应用友系统的配置数据
$add_data['unitcode'] = config('apiu8cloud.SHOP_BASIC_SETUP')[$user_info->adm_shop_id]['unitcode'];//用友-公司编码
$add_data['subjschemecode'] = config('apiu8cloud.SHOP_BASIC_SETUP')[$user_info->adm_shop_id]['subjschemecode'];//用友-科目方案编码
$add_data['bdin_id_json'] = $acsb_data['acss_bdinfo'];//辅助核算项数据
// 调用u8系统接口
$curl_return = $yongyou->u8cloudApi('会计科目从公司新增', $add_data);
// 判断用友接口返回的数据
if ($curl_return['status'] != 'success') {
DB::rollBack();
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'新增科目失败!科目编码已存在!']);
}
if($acsu_id && $acsb_res && $superior_res){
Common::addLog(
$user_info,
getRealIp($request),
'账户管理',
'新增',
'新增科目'.$request['subjname'].'成功'
);
DB::commit();
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'新增科目成功']);
}else{
DB::rollBack();
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'新增科目失败']);
}
}
// 删除
public function delete(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountSubjectController;
$error_message = $verify_data->infoValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$find_data = DB::table('account_subject')
->where('acsu_id', $request['acsu_id'])
->select('subjcode', 'subjname', 'endflag', 'subjlev')
->first();
if ($find_data->endflag != 'Y') {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'不是末级科目无法删除']);
}
// 1. 通过用友的查询接口,查询用友系统这个科目是否已经删除
$yongyou = new YongYouController;
// 获取门店对应用友系统的配置数据
$find_data->unitcode = config('apiu8cloud.SHOP_BASIC_SETUP')[$user_info->adm_shop_id]['unitcode'];//用友-公司编码
$find_data->subjschemecode = config('apiu8cloud.SHOP_BASIC_SETUP')[$user_info->adm_shop_id]['subjschemecode'];//用友-科目方案编码
// 调用u8系统接口
$curl_return = $yongyou->u8cloudApi('会计科目查询', $find_data);
// 判断用友接口返回的数据
if ($curl_return['status'] == 'success') {
// 接口返回成功,判断是否返回科目数据
$success_data = json_decode($curl_return['data'], true);
if ($success_data['allcount']) {
// 返回科目数据,说明用友系统还有科目,门店系统无法删除
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'请先删除用友U8系统的会计科目!']);
}
}else{
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'会计科目删除失败']);
}
DB::beginTransaction();
// 2. 用友系统的科目删除之后,这个科目可以在系统里删除
$acsu_del_res = DB::table('account_subject')
->where('acsu_id', $request['acsu_id'])
->delete();
$acss_del_res = DB::table('account_subject_sublist')
->where('acss_acsu_id', $request['acsu_id'])
->delete();
// 判断是否是一级科目
if ($find_data->subjlev != 1) {
// 不是一级科目,需要判断是否存在同级科目数据
$superior_subjcode = substr($find_data->subjcode, 0, -2);//上级科目编码
// 查询同级科目的数据
$find_sibling = DB::table('account_subject')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('acsu_shop_superior_id', $shop_id)
->where('subjcode', 'like', $superior_subjcode.'%')
->where('subjlev', $find_data->subjlev)
->value('acsu_id');
// 判断同级科目是否全部删除,全部删除之后,上级科目改为 末级
if (empty($find_sibling)) {
// 将上一级的科目 末级标志取值 改为Y:是
$superior_res = DB::table('account_subject')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('acsu_shop_superior_id', $shop_id)
->where('subjcode', $superior_subjcode)
->update(['endflag'=>'Y', 'acsu_update_time'=>date('Y-m-d H:i:s')]);
}else{
$superior_res = true;
}
}else{
$superior_res = true;
}
if($acsu_del_res && $acss_del_res && $superior_res) {
DB::commit();
Common::addLog($user_info, getRealIp($request), '账户科目', '删除', '账户科目 '.$find_data->subjname . '删除成功');
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>'删除成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'删除失败']);
}
}
// 上传凭证搜索-科目
public function searchSubject(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$search_data = $request->all();
$list_data = DB::table('account_subject')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('endflag', 'Y')
->where(function($query) use($search_data) {
if (!empty($search_data['subjcode'])) {
$query->where('subjcode', 'like', '%'.$search_data['subjcode'].'%');
}
}) //科目编码
->where(function($query) use($search_data) {
if (!empty($search_data['subjname'])) {
$query->where('subjname', 'like', '%'.$search_data['subjname'].'%' );
}
}) //科目名称
->select('acsu_id', 'subjcode', 'subjname')
->orderBy('subjcode', 'asc')
->get();
if($list_data) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$list_data]);
}else{
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'暂无数据']);
}
}
// 辅助核算-基础档案资源列表
public function searchBdinfo(Request $request)
{
$search_data = $request->all();
$list_data = DB::table('bdinfo')
->where(function($query) use($search_data) {
if (!empty($search_data['bdname'])) {
$query->where('bdname', 'like', '%'.$search_data['bdname'].'%');
}
}) //基础数据名称
->select('bdin_id', 'bdcode', 'bdname')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
foreach ($list_items as $key => $value) {
$list_items[$key]->print_type = false;//前端使用参数
$list_items[$key]->balance_type = false;//前端使用参数
}
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 搜索科目类型
public function searchSubjectType(Request $request)
{
$search_data = $request->all();
$list_data = DB::table('subject_type')
->where(function($query) use($search_data) {
if (!empty($search_data['subjtypename'])) {
$query->where('subjtypename', 'like', '%'.$search_data['subjtypename'].'%');
}
}) //基础数据名称
->select('typeindex', 'subjtypename')
->paginate($this->show_count);
$list_items = $list_data->items();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 搜索币种
public function searchCurrtype(Request $request)
{
$search_data = $request->all();
$list_data = DB::table('currtype')
->where(function($query) use($search_data) {
if (!empty($search_data['currtypename'])) {
$query->where('currtypename', 'like', '%'.$search_data['currtypename'].'%');
}
}) //基础数据名称
->select('currtypecode', 'currtypename')
->get();
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$list_data]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyAccountTitleController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
use App\Http\Models\Api\Export;
// 银行卡管理
class AccountTitleController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountTitleController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('account_title')
->where('acti_adm_id',$user_info->adm_cid)
->where('acti_shop_superior_id',$shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['acti_subject_code'])) {
$query->where('acti_subject_code', 'like', '%'.$search_data['acti_subject_code'].'%');
}
}) //银行卡代码
->where(function($query) use($search_data) {
if (!empty($search_data['acti_course_title'])) {
$query->where('acti_course_title', 'like', '%'.$search_data['acti_course_title'].'%' );
}
}) //银行卡名称
->where(function($query) use($search_data) {
if (!empty($search_data['acti_state'])) {
$query->where('acti_state', $search_data['acti_state']);
}
}) //状态1启用2停用
->select('acti_id', 'acti_subject_code', 'acti_course_title', 'acti_state', 'acti_initial_count',
'acti_closing_account', 'acti_lend', 'acti_loan')
->orderBy('acti_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 新增
public function add(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountTitleController;
$error_message = $verify_data->addValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 判断银行卡名称是否存在
$acti_id = DB::table('account_title')
->where('acti_adm_id',$user_info->adm_cid)
->where('acti_shop_superior_id',$shop_id)
->where('acti_course_title', $request['acti_course_title'])
->select('acti_id')
->first();
if ($acti_id) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'银行卡名称已存在']);
}
//新增银行卡数据
$acti_add_data['acti_adm_id'] = $user_info->adm_cid; //公司id
$acti_add_data['acti_shop_id'] = $user_info->adm_shop_id; //门店id
$acti_add_data['acti_shop_superior_id'] = $shop_id; //总店id
$acti_add_data['acti_subject_code'] = $request['acti_subject_code']; //银行卡代码
$acti_add_data['acti_course_title'] = $request['acti_course_title']; //银行卡名称
$acti_add_data['acti_state'] = 1; //状态1启用2停用
DB::beginTransaction();
$acti_res = DB::table('account_title')->insertGetId($acti_add_data);
//新增银行卡查询数据
$acse_add_data['acse_acti_id'] = $acti_res; //银行卡id
$acse_add_data['acti_adm_cid'] = $user_info->adm_cid; //公司id
$acse_add_data['acti_shop_id'] = $user_info->adm_shop_id; //门店id
$acse_add_data['acse_year'] = date('Y'); //年份
$acse_add_data['acse_month'] = date('m'); //年份
$acse_add_data['acse_subject_code'] = $request['acti_subject_code']; //银行卡代码
$acse_add_data['acse_course_title'] = $request['acti_course_title']; //银行卡名称
$acti_res = DB::table('account_select')->insert($acse_add_data);
if ($acti_res && $acti_res) {
DB::commit();
Common::addLog($user_info, getRealIp($request), '银行卡管理','新增','新增银行卡:'.$request['acti_course_title'].'成功');
return response()->json(['code'=>200,'msg'=>'success','data'=>'新增银行卡成功']);
}else{
DB::rollBack();
return response()->json(['code'=>500,'msg'=>'error','data'=>'新增银行卡失败']);
}
}
// 编辑
public function edit(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountTitleController;
$error_message = $verify_data->editValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 判断银行卡名称是否存在
$acti_id = DB::table('account_title')
->where('acti_id','<>',$request['acti_id'])
->where('acti_adm_id',$user_info->adm_cid)
->where('acti_shop_superior_id',$shop_id)
->where('acti_course_title', $request['acti_course_title'])
->select('acti_id')
->first();
if ($acti_id) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'银行卡名称已存在']);
}
//编辑数据
$acti_edit_data['acti_subject_code'] = $request['acti_subject_code']; //银行卡代码
$acti_edit_data['acti_course_title'] = $request['acti_course_title']; //银行卡名称
$acti_edit_data['acti_update_time'] = date('Y-m-d H:i:s'); //更新时间
//编辑银行卡查询数据
$acse_edit_data['acse_year'] = date('Y'); //年份
$acse_edit_data['acse_month'] = date('M'); //年份
$acse_edit_data['acse_subject_code'] = $request['acti_subject_code']; //银行卡代码
$acse_edit_data['acse_course_title'] = $request['acti_course_title']; //银行卡名称
$acse_edit_data['acse_update_time'] = date('Y-m-d H:i:s'); //更新时间
DB::beginTransaction();
$acti_res = DB::table('account_title')
->where('acti_id',$request['acti_id'])
->update($acti_edit_data);
// 查询是否有数据
$find_acse_acti_id = DB::table('account_select')
->where('acse_acti_id', $request['acti_id'])
->value('acse_acti_id');
if ($find_acse_acti_id) {
$acse_res = DB::table('account_select')
->where('acse_acti_id', $request['acti_id'])
->update($acse_edit_data);
}else{
$acse_res = true;
}
if ($acti_res && $acse_res) {
DB::commit();
Common::addLog($user_info, getRealIp($request), '银行卡管理','编辑','编辑银行卡:'.$request['acti_course_title'].'成功');
return response()->json(['code'=>200,'msg'=>'success','data'=>'编辑银行卡成功']);
}else{
DB::rollBack();
return response()->json(['code'=>500,'msg'=>'error','data'=>'编辑银行卡失败']);
}
}
// 启用
public function start(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountTitleController;
$error_message = $verify_data->startValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 查询银行卡名称信息
$find_adm = DB::table('account_title')
->whereIn('acti_id',$request['acti_id'])
->select('acti_course_title')
->get();
foreach ($find_adm as $key => $value) {
$acti_course_title[] = $value->acti_course_title;
}
// 启用
$update_data['acti_state'] = 1;//状态1启用2停用
$update_data['acti_update_time'] = date('Y-m-d H:i:s');
$adm_res = DB::table('account_title')
->whereIn('acti_id',$request['acti_id'])
->update($update_data);
if($adm_res) {
Common::addLog($user_info, getRealIp($request), '银行卡管理','启用','银行卡名称:('.implode(',', $acti_course_title).')启用成功');
return response()->json(['code'=>200,'msg'=>'success','data'=>'启用成功']);
}else{
return response()->json(['code'=>500,'msg'=>'error','data'=>'启用失败']);
}
}
// 停用
public function stop(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountTitleController;
$error_message = $verify_data->startValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 查询银行卡名称信息
$find_adm = DB::table('account_title')
->whereIn('acti_id',$request['acti_id'])
->select('acti_course_title')
->get();
foreach ($find_adm as $key => $value) {
$acti_course_title[] = $value->acti_course_title;
}
// 停用
$update_data['acti_state'] = 2;//状态1启用2停用
$update_data['acti_update_time'] = date('Y-m-d H:i:s');
$adm_res = DB::table('account_title')
->whereIn('acti_id',$request['acti_id'])
->update($update_data);
if($adm_res) {
Common::addLog($user_info, getRealIp($request), '银行卡管理','停用','银行卡名称:('.implode(',', $acti_course_title).')停用成功');
return response()->json(['code'=>200,'msg'=>'success','data'=>'停用成功']);
}else{
return response()->json(['code'=>500,'msg'=>'error','data'=>'停用失败']);
}
}
// 银行卡查询列表
public function selectIndex(Request $request)
{
// 验证数据
$verify_data = new VerifyAccountTitleController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$search_data = $request->all();
$list_data = DB::table('account_select')
->where('acti_adm_cid',$user_info->adm_cid)
->where('acti_shop_id',$user_info->adm_shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['acti_subject_code'])) {
$query->where('acse_subject_code', 'like', '%'.$search_data['acti_subject_code'].'%');
}
}) //银行卡代码
->where(function($query) use($search_data) {
if (!empty($search_data['acti_course_title'])) {
$query->where('acse_course_title', 'like', '%'.$search_data['acti_course_title'].'%' );
}
}) //银行卡名称
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_acse_year']) && !empty($search_data['end_acse_year'])){
$query->whereBetween('acse_year',[$search_data['start_acse_year'],$search_data['end_acse_year']]);
}else{
// 如果选择开始时间
if (!empty($search_data['start_acse_year'])){
$query->where('acse_year','>=',$search_data['start_acse_year']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_acse_year'])) {
$query->where('acse_year','<=',$search_data['end_acse_year']);
}
}
}
}) //年份
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_acse_month']) && !empty($search_data['end_acse_month'])){
$query->whereBetween('acse_month',[$search_data['start_acse_month'],$search_data['end_acse_month']]);
}else{
// 如果选择开始时间
if (!empty($search_data['start_acse_month'])){
$query->where('acse_month','>=',$search_data['start_acse_month']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_acse_month'])) {
$query->where('acse_month','<=',$search_data['end_acse_month']);
}
}
}
}) //月份
->select('acse_id', 'acse_year', 'acse_month', 'acse_subject_code', 'acse_course_title',
'acse_initial_count', 'acse_lend', 'acse_loan', 'acse_closing_account')
->orderBy('acse_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
$sum_type = 1; //隐藏
// 判断是否有搜索条件 有搜索条件
if(!empty($search_data['acti_subject_code']) || !empty($search_data['acti_course_title']) || !empty($search_data['start_acse_year']) | !empty($search_data['end_acse_year']) || !empty($search_data['start_acse_month']) || !empty($search_data['end_acse_month'])){
$sum_type = 2;
$sum_data = DB::table('account_select')
->where('acti_adm_cid',$user_info->adm_cid)
->where('acti_shop_id',$user_info->adm_shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['acti_subject_code'])) {
$query->where('acse_subject_code', 'like', '%'.$search_data['acti_subject_code'].'%');
}
}) //银行卡代码
->where(function($query) use($search_data) {
if (!empty($search_data['acti_course_title'])) {
$query->where('acse_course_title', 'like', '%'.$search_data['acti_course_title'].'%' );
}
}) //银行卡名称
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_acse_year']) && !empty($search_data['end_acse_year'])){
$query->whereBetween('acse_year',[$search_data['start_acse_year'],$search_data['end_acse_year']]);
}else{
// 如果选择开始时间
if (!empty($search_data['start_acse_year'])){
$query->where('acse_year','>=',$search_data['start_acse_year']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_acse_year'])) {
$query->where('acse_year','<=',$search_data['end_acse_year']);
}
}
}
}) //年份
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_acse_month']) && !empty($search_data['end_acse_month'])){
$query->whereBetween('acse_month',[$search_data['start_acse_month'],$search_data['end_acse_month']]);
}else{
// 如果选择开始时间
if (!empty($search_data['start_acse_month'])){
$query->where('acse_month','>=',$search_data['start_acse_month']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_acse_month'])) {
$query->where('acse_month','<=',$search_data['end_acse_month']);
}
}
}
}) //月份
->first(array(
\DB::raw('SUM(acse_lend) as lend'), //借
\DB::raw('SUM(acse_loan) as loan'), //贷
\DB::raw('SUM(acse_initial_count) as initial_count'), //期初余额
\DB::raw('SUM(acse_closing_account) as closing_account'), //期末余额
));
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['sum_type'] = $sum_type; //返回总数量
$data_info['lend'] = empty($sum_data->lend)?0:$sum_data->lend; //借
$data_info['loan'] = empty($sum_data->loan)?0:$sum_data->loan; //贷
$data_info['initial_count'] = empty($sum_data->initial_count)?0:$sum_data->initial_count; //期初余额
$data_info['closing_account'] = empty($sum_data->closing_account)?0:$sum_data->closing_account; //期末余额
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 导出
public function export(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$search_data = $request->all();
$data = DB::table('account_select')
->where('acti_adm_cid',$user_info->adm_cid)
->where('acti_shop_id',$user_info->adm_shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['acti_subject_code'])) {
$query->where('acse_subject_code', 'like', '%'.$search_data['acti_subject_code'].'%');
}
}) //银行卡代码
->where(function($query) use($search_data) {
if (!empty($search_data['acti_course_title'])) {
$query->where('acse_course_title', 'like', '%'.$search_data['acti_course_title'].'%' );
}
}) //银行卡名称
->where(function($query) use($search_data) {
if (!empty($search_data['acse_year'])) {
$query->where('acse_year', 'like', '%'.$search_data['acse_year'].'%' );
}
}) //年份
->where(function($query) use($search_data) {
if (!empty($search_data['acse_month'])) {
$query->where('acse_month', 'like', '%'.$search_data['acse_month'].'%' );
}
}) //月份
->select('acse_year', 'acse_month', 'acse_subject_code', 'acse_course_title', 'acse_initial_count',
'acse_lend', 'acse_loan', 'acse_closing_account')
->orderBy('acse_id', 'desc')
->get()->toArray();
if (!empty($data)) {
// 将对象转化为数组
$data = json_decode(json_encode($data),true);
foreach ($data as $key => $value) {
$data[$key]['acse_initial_count'] = $value['acse_initial_count'] / 100;
$data[$key]['acse_lend'] = $value['acse_lend'] / 100;
$data[$key]['acse_loan'] = $value['acse_loan'] / 100;
$data[$key]['acse_closing_account'] = $value['acse_closing_account'] / 100;
}
} else {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'暂无导出数据']);
}
$pathName = storage_path()."/app/public/excel";//获取上传excel路径
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName,0775,true);
chmod($pathName,0775);
}
$streamFileRand = time() . rand(10000,99999).'.xls';//
// 产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
$streamFilename = $pathName . '/' .$streamFileRand;
$where['action_name'] = '银行卡查询'; //
$where['field_name'] = ['年份','月份','银行卡代码','银行卡名称','期初余额','借(汇入)','贷(汇出)','期末余额'];
// 调用导出的公共方法
export::publicExport(
$streamFilename, //路径
$where, //sheet名及其每一行的标题
$data //导出数据
);
// 判断文件是否存在 存在则成功 不存在则失败
if(file_exists($pathName))
{
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>'storage/excel/'.$streamFileRand]);
}else{
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'导出失败']);
}
}
// 银行卡查询列表打印
public function print(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$search_data = $request->all();
$list_data = DB::table('account_select')
->where('acti_adm_cid',$user_info->adm_cid)
->where('acti_shop_id',$user_info->adm_shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['acti_subject_code'])) {
$query->where('acse_subject_code', 'like', '%'.$search_data['acti_subject_code'].'%');
}
}) //银行卡代码
->where(function($query) use($search_data) {
if (!empty($search_data['acti_course_title'])) {
$query->where('acse_course_title', 'like', '%'.$search_data['acti_course_title'].'%' );
}
}) //银行卡名称
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_acse_year']) && !empty($search_data['end_acse_year'])){
$query->whereBetween('acse_year',[$search_data['start_acse_year'],$search_data['end_acse_year']]);
}else{
// 如果选择开始时间
if (!empty($search_data['start_acse_year'])){
$query->where('acse_year','>=',$search_data['start_acse_year']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_acse_year'])) {
$query->where('acse_year','<=',$search_data['end_acse_year']);
}
}
}
}) //年份
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_acse_month']) && !empty($search_data['end_acse_month'])){
$query->whereBetween('acse_month',[$search_data['start_acse_month'],$search_data['end_acse_month']]);
}else{
// 如果选择开始时间
if (!empty($search_data['start_acse_month'])){
$query->where('acse_month','>=',$search_data['start_acse_month']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_acse_month'])) {
$query->where('acse_month','<=',$search_data['end_acse_month']);
}
}
}
}) //月份
->select('acse_id', 'acse_year', 'acse_month', 'acse_subject_code', 'acse_course_title',
'acse_initial_count', 'acse_lend', 'acse_loan', 'acse_closing_account')
->orderBy('acse_id', 'desc')
->get();
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$list_data]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyInitialBalanceController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
// 期初余额
class InitialBalanceController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyInitialBalanceController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('account_subject')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('subjlev', 1)
->where(function($query) use($search_data) {
if (!empty($search_data['subjcode'])) {
$query->where('subjcode', 'like', '%'.$search_data['subjcode'].'%');
}
}) //科目编码
->where(function($query) use($search_data) {
if (!empty($search_data['subjname'])) {
$query->where('subjname', 'like', '%'.$search_data['subjname'].'%' );
}
}) //科目名称
->select('acsu_id', 'subjcode', 'subjname', 'balanorient', 'unit', 'endflag', 'acsu_bdin_id')
->orderBy('acsu_id', 'asc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
// 查询期末余额数据
$acsu_id = array_column($list_items, 'acsu_id');
$find_acib_data = DB::table('account_initial_balance')
->where('acib_cid', $user_info->adm_cid)
->where('acib_shop_id', $user_info->adm_shop_id)
->where('currtypecode', $search_data['currtypecode'])
->whereIn('acib_acsu_id', $acsu_id)
->select('acib_id', 'acib_acsu_id', 'debtor_amount', 'debtor_original_currency',
'debtor_home_currency', 'creditor_amount', 'creditor_original_currency', 'creditor_home_currency', 'initial_amount',
'initial_original_currency', 'initial_home_currency', 'beginning_amount', 'beginning_original_currency',
'beginning_home_currency')
->get()->toArray();
$acib_data = array_column($find_acib_data, null, 'acib_acsu_id');
// 将查询出的期末余额表数据赋值给相关科目
foreach ($list_items as $key => $value) {
if (isset($acib_data[$value->acsu_id])) {
// 合并两个对象数据
$list_items[$key] = (object)array_merge((array)$value, (array)$acib_data[$value->acsu_id]);
}
}
$list_items = $this->inquireChildren($user_info, $list_items, $search_data, 1);
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 编辑
public function edit(Request $request)
{
// 验证数据
$verify_data = new VerifyInitialBalanceController;
$error_message = $verify_data->editValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 查询科目是否是末级
$find_data = DB::table('account_subject')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_superior_id', $shop_id)
->where('acsu_id', $request['acsu_id'])
->select('subjcode', 'subjname', 'subjlev', 'endflag', 'balanorient')
->first();
if ($find_data->endflag != 'Y') {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'不是末级科目无法编辑']);
}
if ($user_info->adm_id != 1) {
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>'期初余额编辑成功']);
}
$creditor_original_currency = empty($request['creditor_original_currency']) ? 0 : $request['creditor_original_currency'];
$debtor_original_currency = empty($request['debtor_original_currency']) ? 0 : $request['debtor_original_currency'];
$initial_original_currency = empty($request['initial_original_currency']) ? 0 : $request['initial_original_currency'];
$acib_data['debtor_original_currency'] = $debtor_original_currency;//借方原币
$acib_data['debtor_home_currency'] = $debtor_original_currency;//借方本币
$acib_data['creditor_original_currency'] = $creditor_original_currency;//贷方原币
$acib_data['creditor_home_currency'] = $creditor_original_currency;//贷方本币
$acib_data['initial_original_currency'] = $initial_original_currency;//期初原币
$acib_data['initial_home_currency'] = $initial_original_currency;//期初本币
// 科目方向是借:年初原币计算 = 贷方-借方+期初
// 科目方向是贷:年初原币计算 = 借方-贷方+期初
// 期初余额的上级金额,下级的贷 100 上级的借 -100,借贷不一样,金额是相反的
// balanorient 余额方向 1:借2:贷
if ($find_data->balanorient == 1) {
$initial_home_currency = $creditor_original_currency - $debtor_original_currency + $initial_original_currency;
}else{
$initial_home_currency = $debtor_original_currency - $creditor_original_currency + $initial_original_currency;
}
$acib_data['beginning_original_currency'] = $initial_home_currency;//年初原币
$acib_data['beginning_home_currency'] = $initial_home_currency;//年初本币
DB::beginTransaction();
// 判断是否为一级科目
if ($find_data->subjlev != 1) {
$first_code = substr($find_data->subjcode, 0, 4);//一级编码,前四位是一级编码
$subjlev_rank = [4,2,2,2];//级别对应的位数
$subjlev = $find_data->subjlev - 1;//科目级别
$rank = 0;
// 上级科目编码
foreach ($subjlev_rank as $key => $value) {
$rank += $value;
if ($key < $subjlev) {
$rank_code[] = substr($find_data->subjcode, 0, $rank);//要更改金额的上级科目编码
}
}
// 查询出上级的科目
$rank_acsu_data = DB::table('account_subject')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_superior_id', $shop_id)
->where('subjcode', 'like', $first_code.'%')
->where('subjlev', '<', $find_data->subjlev)
->whereIn('subjcode', $rank_code)
->select('acsu_id', 'subjcode', 'subjname', 'subjlev', 'endflag', 'balanorient')
->get()->toArray();
$acsu_id = array_column($rank_acsu_data, 'acsu_id');//科目id
// 查询上级科目的期初余额数据
$find_rank_acib = DB::table('account_initial_balance')
->where('acib_cid', $user_info->adm_cid)
->where('acib_shop_superior_id', $shop_id)
->whereIn('acib_acsu_id', $acsu_id)
->where('currtypecode', $request['currtypecode'])//币种编码
->select('acib_id', 'acib_acsu_id', 'debtor_original_currency', 'debtor_home_currency', 'creditor_original_currency',
'creditor_home_currency', 'initial_original_currency', 'initial_home_currency', 'beginning_original_currency',
'beginning_home_currency')
->get()->toArray();
// 判断期初余额是否存在
if (empty($find_rank_acib)) {
$rank_add_data = [];
// 不存在就新增
foreach ($rank_acsu_data as $key => $value) {
$rank_add_data[$key]['acib_cid'] = $user_info->adm_cid;
$rank_add_data[$key]['acib_shop_id'] = $user_info->adm_shop_id;
$rank_add_data[$key]['acib_shop_superior_id'] = $shop_id;
$rank_add_data[$key]['acib_acsu_id'] = $value->acsu_id;//账户科目id
$rank_add_data[$key]['currtypecode'] = $request['currtypecode'];//币种编码
$rank_add_data[$key]['debtor_original_currency'] = $debtor_original_currency;//借方原币
$rank_add_data[$key]['debtor_home_currency'] = $debtor_original_currency;//借方本币
$rank_add_data[$key]['creditor_original_currency'] = $creditor_original_currency;//贷方原币
$rank_add_data[$key]['creditor_home_currency'] = $creditor_original_currency;//贷方本币
// 判断上级科目的方向 跟 编辑科目的方向是否一致
if ($find_data->balanorient == $value->balanorient) {
// 方向一致,上级科目的期初余额加上相同的金额
$rank_add_data[$key]['initial_original_currency'] = $initial_original_currency;//期初原币
$rank_add_data[$key]['initial_home_currency'] = $initial_original_currency;//期初本币
// 科目方向是借:年初原币计算 = 贷方-借方+期初
// 科目方向是贷:年初原币计算 = 借方-贷方+期初
// balanorient 余额方向 1:借2:贷
if ($value->balanorient == 1) {
$initial_home_currency = $creditor_original_currency - $debtor_original_currency + $initial_original_currency;
}else{
$initial_home_currency = $debtor_original_currency - $creditor_original_currency + $initial_original_currency;
}
}else{
// 方向不一致,上级科目的期初余额减去相同的金额
$rank_add_data[$key]['initial_original_currency'] = '-'.$initial_original_currency;//期初原币
$rank_add_data[$key]['initial_home_currency'] = '-'.$initial_original_currency;//期初本币
// balanorient 余额方向 1:借2:贷
if ($value->balanorient == 1) {
$initial_home_currency = $creditor_original_currency - $debtor_original_currency - $initial_original_currency;
}else{
$initial_home_currency = $debtor_original_currency - $creditor_original_currency - $initial_original_currency;
}
}
$rank_add_data[$key]['beginning_original_currency'] = $initial_home_currency;//年初原币
$rank_add_data[$key]['beginning_home_currency'] = $initial_home_currency;//年初本币
}
$rank_add_res = DB::table('account_initial_balance')->insert($rank_add_data);
if (!$rank_add_res) {
DB::rollBack();
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'期初余额编辑失败']);
}
}else{
// 存在就编辑数据
$rank_acib_data = array_column($find_rank_acib, null, 'acib_acsu_id');
$num = 0;
foreach ($rank_acsu_data as $key => $value) {
// 判断上级科目的期初余额是否存在
if (isset($rank_acib_data[$value->acsu_id])) {
$new_creditor_original_currency = $creditor_original_currency - $rank_acib_data[$value->acsu_id]->creditor_original_currency;
$new_debtor_original_currency = $debtor_original_currency - $rank_acib_data[$value->acsu_id]->debtor_original_currency;
$new_initial_original_currency = $initial_original_currency - $rank_acib_data[$value->acsu_id]->initial_original_currency;
$rank_data['debtor_original_currency'] = $rank_acib_data[$value->acsu_id]->debtor_original_currency + $new_debtor_original_currency;//借方原币
$rank_data['debtor_home_currency'] = $rank_acib_data[$value->acsu_id]->debtor_home_currency + $new_debtor_original_currency;//借方本币
$rank_data['creditor_original_currency'] = $rank_acib_data[$value->acsu_id]->creditor_original_currency + $new_creditor_original_currency;//贷方原币
$rank_data['creditor_home_currency'] = $rank_acib_data[$value->acsu_id]->creditor_home_currency + $new_creditor_original_currency;//贷方本币
// 判断上级科目的方向 跟 编辑科目的方向是否一致
if ($find_data->balanorient == $value->balanorient) {
// 方向一致,上级科目的期初余额加上相同的金额
$rank_data['initial_original_currency'] = $rank_acib_data[$value->acsu_id]->initial_original_currency + $new_initial_original_currency;//期初原币
$rank_data['initial_home_currency'] = $rank_acib_data[$value->acsu_id]->initial_home_currency + $new_initial_original_currency;//期初本币
// 科目方向是借:年初原币计算 = 贷方-借方+期初
// 科目方向是贷:年初原币计算 = 借方-贷方+期初
// balanorient 余额方向 1:借2:贷
if ($value->balanorient == 1) {
$initial_home_currency = $new_creditor_original_currency - $new_debtor_original_currency + $new_initial_original_currency;
}else{
$initial_home_currency = $new_debtor_original_currency - $new_creditor_original_currency + $new_initial_original_currency;
}
}else{
// 方向不一致,上级科目的期初余额减去相同的金额
$rank_data['initial_original_currency'] = $rank_acib_data[$value->acsu_id]->initial_original_currency - $new_initial_original_currency;//期初原币
$rank_data['initial_home_currency'] = $rank_acib_data[$value->acsu_id]->initial_home_currency - $new_initial_original_currency;//期初本币
// balanorient 余额方向 1:借2:贷
if ($value->balanorient == 1) {
$initial_home_currency = $new_creditor_original_currency - $new_debtor_original_currency - $new_initial_original_currency;
}else{
$initial_home_currency = $new_debtor_original_currency - $new_creditor_original_currency - $new_initial_original_currency;
}
}
$rank_data['beginning_original_currency'] = $rank_acib_data[$value->acsu_id]->beginning_original_currency + $initial_home_currency;//年初原币
$rank_data['beginning_home_currency'] = $rank_acib_data[$value->acsu_id]->beginning_home_currency + $initial_home_currency;//年初本币
$rank_edit_res = DB::table('account_initial_balance')
->where('acib_id', $rank_acib_data[$value->acsu_id]->acib_id)
->update($rank_data);
if (!$rank_edit_res) {
DB::rollBack();
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'期初余额编辑失败']);
}
}else{
$rank_add_data[$num]['acib_cid'] = $user_info->adm_cid;
$rank_add_data[$num]['acib_shop_id'] = $user_info->adm_shop_id;
$rank_add_data[$num]['acib_shop_superior_id'] = $shop_id;
$rank_add_data[$num]['acib_acsu_id'] = $value->acsu_id;//账户科目id
$rank_add_data[$num]['currtypecode'] = $request['currtypecode'];//币种编码
$rank_add_data[$num]['debtor_original_currency'] = $debtor_original_currency;//借方原币
$rank_add_data[$num]['debtor_home_currency'] = $debtor_original_currency;//借方本币
$rank_add_data[$num]['creditor_original_currency'] = $creditor_original_currency;//贷方原币
$rank_add_data[$num]['creditor_home_currency'] = $creditor_original_currency;//贷方本币
// 判断上级科目的方向 跟 编辑科目的方向是否一致
if ($find_data->balanorient == $value->balanorient) {
// 方向一致,上级科目的期初余额加上相同的金额
$rank_add_data[$num]['initial_original_currency'] = $initial_original_currency;//期初原币
$rank_add_data[$num]['initial_home_currency'] = $initial_original_currency;//期初本币
// 科目方向是借:年初原币计算 = 贷方-借方+期初
// 科目方向是贷:年初原币计算 = 借方-贷方+期初
// balanorient 余额方向 1:借2:贷
if ($value->balanorient == 1) {
$initial_home_currency = $creditor_original_currency - $debtor_original_currency + $initial_original_currency;
}else{
$initial_home_currency = $debtor_original_currency - $creditor_original_currency + $initial_original_currency;
}
}else{
// 方向不一致,上级科目的期初余额减去相同的金额
$rank_add_data[$num]['initial_original_currency'] = '-'.$initial_original_currency;//期初原币
$rank_add_data[$num]['initial_home_currency'] = '-'.$initial_original_currency;//期初本币
// balanorient 余额方向 1:借2:贷
if ($value->balanorient == 1) {
$initial_home_currency = $creditor_original_currency - $debtor_original_currency - $initial_original_currency;
}else{
$initial_home_currency = $debtor_original_currency - $creditor_original_currency - $initial_original_currency;
}
}
$rank_add_data[$num]['beginning_original_currency'] = $initial_home_currency;//年初原币
$rank_add_data[$num]['beginning_home_currency'] = $initial_home_currency;//年初本币
$num++;
}
}
if (empty($rank_add_data)) {
$rank_add_res = true;
}else{
$rank_add_res = DB::table('account_initial_balance')->insert($rank_add_data);
}
if (!$rank_add_res) {
DB::rollBack();
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'期初余额编辑失败']);
}
}
}
// 查询期初余额表数据
$acib_id = DB::table('account_initial_balance')
->where('acib_cid', $user_info->adm_cid)
->where('acib_shop_superior_id', $shop_id)
->where('acib_acsu_id', $request['acsu_id'])
->where('currtypecode', $request['currtypecode'])
->value('acib_id');
// 判断是否有期初余额id
if (!empty($acib_id)) {
// 编辑
$acib_data['acib_update_time'] = date('Y-m-d H:i:s');
$acib_res = DB::table('account_initial_balance')
->where('acib_cid', $user_info->adm_cid)
->where('acib_shop_superior_id', $shop_id)
->where('acib_id', $acib_id)
->update($acib_data);
} else {
// 新增
$acib_data['acib_cid'] = $user_info->adm_cid;
$acib_data['acib_shop_id'] = $user_info->adm_shop_id;
$acib_data['acib_shop_superior_id'] = $shop_id;
$acib_data['acib_acsu_id'] = $request['acsu_id'];//账户科目id
$acib_data['currtypecode'] = $request['currtypecode'];//币种编码
$acib_res = DB::table('account_initial_balance')
->insert($acib_data);
}
if($acib_res) {
DB::commit();
Common::addLog($user_info, getRealIp($request), '期初余额', '编辑', '期初余额 '.$find_data->subjname . '编辑成功');
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>'期初余额编辑成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'期初余额编辑失败']);
}
}
/**
* [inquireChildren 搜索下级数据]
* @param [type] $user_info [用户信息]
* @param [type] $data [列表数据]
* @param integer $subjlev [科目级数]
* @return [type] [description]
*/
private function inquireChildren($user_info, $data, $search_data, $subjlev = 1)
{
$subjlev = $subjlev + 1;//科目级次
foreach ($data as $key => $value) {
if ($value->endflag == 'N') {
$children = DB::table('account_subject as acsu')
->where('acsu_cid', $user_info->adm_cid)
->where('acsu_shop_id', $user_info->adm_shop_id)
->where('subjcode', 'like', $value->subjcode.'%' )
->where('subjlev', $subjlev)
->select('acsu_id', 'subjcode', 'subjname', 'balanorient', 'unit', 'endflag', 'acsu_bdin_id')
->get()->toArray();
// 查询期末余额数据
$acsu_id = array_column($children, 'acsu_id');
$find_acib_data = DB::table('account_initial_balance')
->where('acib_cid', $user_info->adm_cid)
->where('acib_shop_id', $user_info->adm_shop_id)
->where('currtypecode', $search_data['currtypecode'])
->whereIn('acib_acsu_id', $acsu_id)
->select('acib_id', 'acib_acsu_id', 'debtor_amount', 'debtor_original_currency',
'debtor_home_currency', 'creditor_amount', 'creditor_original_currency', 'creditor_home_currency', 'initial_amount',
'initial_original_currency', 'initial_home_currency', 'beginning_amount', 'beginning_original_currency',
'beginning_home_currency')
->get()->toArray();
$acib_data = array_column($find_acib_data, null, 'acib_acsu_id');
// 将查询出的期末余额表数据赋值给相关科目
foreach ($children as $chil_key => $chil_value) {
if (isset($acib_data[$chil_value->acsu_id])) {
// 合并两个对象数据
$children[$chil_key] = (object)array_merge((array)$chil_value, (array)$acib_data[$chil_value->acsu_id]);
}
}
// 递归查询下一级的数据
$data[$key]->children = $this->inquireChildren($user_info, $children, $search_data, $subjlev);
unset($children);
unset($acsu_id);
unset($find_acib_data);
unset($acib_data);
}
}
return $data;
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Models\Api\Common;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
// use App\Http\Controllers\Api\Verify\AccountControl\VerifyMatchOrderController;
use App\Http\Models\Api\Export;
// 对单列表
class MatchOrderController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 对单列表
public function index(Request $request)
{
// 验证数据
if (empty($request['pri_id'])) {
return response()->json(['code' => 500, 'msg' => 'error', 'data' => '参数错误']);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$orderby_type = 'desc'; //排序类型,默认倒序查询
// 当查询待接单状态订单时,按正序查询
if (!empty($request['ord_wor_state']) && $request['ord_wor_state'] == 7) {
$orderby_type = 'asc'; //默认排序类型
}
$list_data = DB::table('order as a')
->leftJoin('order_client as b', 'b.orcl_ord_id', '=', 'a.ord_id')
->leftJoin('channel_unit as cu', 'cu.chun_id', '=', 'a.ord_client_id')
->leftJoin('admin as as', 'as.adm_id', '=', 'a.ord_create_id')
->where('ord_cid', $user_info->adm_cid)
->where('ord_superior_shop_id', $shop_id)
->where('ord_delete', 1)
->where('ord_collection_bill', 1) //是否代收账单:1正常订单2代收账单
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_order_number'])) {
$query->where('ord_order_number', 'like', '%' . $search_data['ord_order_number'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_channel_unit'])) {
$query->where('orcl_channel_unit', 'like', '%' . $search_data['orcl_channel_unit'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_name'])) {
$query->where('orcl_name', 'like', '%' . $search_data['orcl_name'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_type'])) {
$query->where('ord_type', $search_data['ord_type']);
}
}) //买家类型:1会员零售2客户单位3速电网单
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_service_type'])) {
$query->where('ord_service_type', $search_data['ord_service_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_create_id'])) {
$query->where('a.ord_create_id', $search_data['ord_create_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_state'])) {
$query->where('ord_state', $search_data['ord_state']);
}
})
->where(function ($query) use ($search_data) {
// 订单完成状态4已完成,其他值是未完成
if (!empty($search_data['ord_wor_state'])) {
if ($search_data['ord_wor_state'] == 4) {
$query->where('ord_wor_state', $search_data['ord_wor_state']);
} else {
$query->where('ord_wor_state', '<>', 4);
}
}
})
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['create_time_start']) && !empty($search_data['create_time_end'])) {
$query->whereBetween('ord_create_time', [$search_data['create_time_start'], $search_data['create_time_end'] . ' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['create_time_start'])) {
$query->where('ord_create_time', '>=', $search_data['create_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['create_time_end'])) {
$query->where('ord_create_time', '<=', $search_data['create_time_end'] . ' 23:59:59');
}
}
}
}) //创建时间
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_form_type'])) {
$query->where('ord_form_type', $search_data['ord_form_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_shipment_party'])) {
$query->where('orcl_shipment_party', $search_data['orcl_shipment_party']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_service_shop_id'])) {
$query->where('ord_service_shop_id', $search_data['ord_service_shop_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_client_id'])) {
$query->where('ord_client_id', $search_data['ord_client_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_match_type'])) {
$query->where('orcl_match_type', $search_data['orcl_match_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ware_id'])) {
$query->where('ord_ware_id', $search_data['ware_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_payment_way'])) {
$query->where('ord_payment_way', $search_data['ord_payment_way']);
}
}) //结算方式1.账期 2.现结 3微信 4支付宝
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_match_adm_id'])) {
$query->where('orcl_match_adm_id', $search_data['orcl_match_adm_id']);
}
})//对单人
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['match_time_start']) && !empty($search_data['match_time_end'])) {
$query->whereBetween('orcl_match_time', [$search_data['match_time_start'], $search_data['match_time_end'] . ' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['match_time_start'])) {
$query->where('orcl_match_time', '>=', $search_data['match_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['match_time_end'])) {
$query->where('orcl_match_time', '<=', $search_data['match_time_end'] . ' 23:59:59');
}
}
}
})//对单时间
->select('ord_id', 'ord_order_number', 'adm_name', 'chun_unit_name', 'ord_actual_price', 'ord_create_time', 'ord_service_type', 'orcl_match_type', 'ord_client_id', 'orcl_shipment_party', 'ord_type', 'ord_ware_id', 'ord_plus_minus', 'ord_payment_way', 'orcl_match_adm_id', 'orcl_match_time', 'orcl_name', 'ord_wor_state')
->orderBy('ord_id', $orderby_type)
->paginate($this->show_count);
$list_items = $list_data->items();
$ord_client_one = [];
$ord_client_two = [];
$ord_client_four = [];
$ware_id = [];
if ($list_items) {
// 将对象转化为数组
$list_items = json_decode(json_encode($list_items), true);
$ord_client_id = array_column($list_items, 'ord_client_id');
// 会员零售
$mem = DB::table('member')
->whereIn('mem_id', $ord_client_id)
->pluck('mem_name', 'mem_id');
// 查询客户单位
$channel = DB::table('channel_unit')
->whereIn('chun_id', $ord_client_id)
->pluck('chun_unit_name', 'chun_id');
// 虚拟加盟店
$virtual = DB::table('virtual_shop')
->whereIn('vish_id', $ord_client_id)
->pluck('vish_name', 'vish_id');
$ware_id = array_column($list_items, 'ord_ware_id');
$orcl_match_adm_id = array_column($list_items, 'orcl_match_adm_id');
// 仓库
$ware = DB::table('warehouse')
->whereIn('ware_id', $ware_id)
->pluck('ware_name', 'ware_id');
// 对单人
$match_name = DB::table('admin')
->whereIn('adm_id', $orcl_match_adm_id)
->pluck('adm_name', 'adm_id');
foreach ($list_items as $key => $value) {
$list_items[$key]['ord_order_number'] = $value['ord_order_number'];
$list_items[$key]['adm_name'] = $value['adm_name'];
if ($value['ord_type'] == 1) {
if (empty($mem[$value['ord_client_id']])) {
$list_items[$key]['chun_unit_name'] = $value['orcl_name'];
} else {
$list_items[$key]['chun_unit_name'] = $mem[$value['ord_client_id']];
}
} elseif ($value['ord_type'] == 2) {
$list_items[$key]['chun_unit_name'] = $channel[$value['ord_client_id']];
} elseif ($value['ord_type'] == 3) {
$list_items[$key]['chun_unit_name'] = config('apisystem.sd_chan_info')['name'];
} elseif ($value['orcl_shipment_party'] == 4) {
$list_items[$key]['chun_unit_name'] = $virtual[$value['ord_client_id']];
}
$list_items[$key]['ord_actual_price'] = $value['ord_actual_price']; //结算金额
if (isset($ware[$value['ord_ware_id']])) {
$list_items[$key]['ware_name'] = $ware[$value['ord_ware_id']];
} else {
$list_items[$key]['ware_name'] = '';
}
//对单人
if (isset($match_name[$value['orcl_match_adm_id']])) {
$list_items[$key]['orcl_match_name'] = $match_name[$value['orcl_match_adm_id']];
} else {
$list_items[$key]['orcl_match_name'] = '';
}
}
}
// 查询门店打印模板
$shpt_data = DB::table('shop_print_template')
->where('shpt_shop_id', $user_info->adm_shop_id)
->whereIn('shpt_print_type', [14])
->where('shpt_delete', 1)
->select('shpt_id', 'shpt_print_type', 'shpt_isdefault')
->get()->toArray();
if (empty($shpt_data)) {
$shpt_data = [];
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['shpt_data'] = $shpt_data; //模板id
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
}
// 确认
public function affirm(Request $request)
{
// 验证数据
if (empty($request['ord_id'])) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误']);
}
//获取用户信息
$user_info = Common::getUserInfo($request['api_token']);
$ord_order_number = DB::table('order')->where('ord_id', $request['ord_id'])->value('ord_order_number');
$update_data['orcl_match_type'] = 2;
$update_data['orcl_update_time'] = date('Y-m-d H:i:s');
$update_data['orcl_match_adm_id'] = $user_info->adm_id;
$update_data['orcl_match_time'] = date('Y-m-d H:i:s');
$res = DB::table('order_client')
->where('orcl_ord_id', $request['ord_id'])
->update($update_data);
if ($res) {
Common::addLog($user_info, getRealIp($request), '对单列表', '确认对单', '订单:' . $ord_order_number);
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'确认对单成功']);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'确认对单失败']);
}
}
// 取消确认
public function unAffirm(Request $request)
{
// 验证数据
if (empty($request['ord_id'])) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误']);
}
//获取用户信息
$user_info = Common::getUserInfo($request['api_token']);
$ord_order_number = DB::table('order')->where('ord_id', $request['ord_id'])->value('ord_order_number');
$res = DB::table('order_client')
->where('orcl_ord_id', $request['ord_id'])
->update(['orcl_match_type' => 1, 'orcl_update_time' => date('Y-m-d H:i:s'), 'orcl_match_adm_id' => '', 'orcl_match_time' => '0000-00-00 00:00:00']);
if ($res) {
Common::addLog($user_info, getRealIp($request), '对单列表', '取消对单', '订单:' . $ord_order_number);
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'取消对单成功']);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'取消对单失败']);
}
}
// 打印
public function print(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$orderby_type = 'desc'; //排序类型,默认倒序查询
// 当查询待接单状态订单时,按正序查询
if (!empty($request['ord_wor_state']) && $request['ord_wor_state'] == 7) {
$orderby_type = 'asc'; //默认排序类型
}
$data = DB::table('order as a')
->leftJoin('order_client as b', 'b.orcl_ord_id', '=', 'a.ord_id')
->leftJoin('admin as as', 'as.adm_id', '=', 'a.ord_create_id')
->where('ord_cid', $user_info->adm_cid)
->where('ord_superior_shop_id', $shop_id)
->where('ord_delete', 1)
->where('ord_collection_bill', 1) //是否代收账单:1正常订单2代收账单
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_order_number'])) {
$query->where('ord_order_number', 'like', '%' . $search_data['ord_order_number'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_channel_unit'])) {
$query->where('orcl_channel_unit', 'like', '%' . $search_data['orcl_channel_unit'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_name'])) {
$query->where('orcl_name', 'like', '%' . $search_data['orcl_name'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_type'])) {
$query->where('ord_type', $search_data['ord_type']);
}
}) //买家类型:1会员零售2客户单位3速电网单
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_service_type'])) {
$query->where('ord_service_type', $search_data['ord_service_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_create_id'])) {
$query->where('a.ord_create_id', $search_data['ord_create_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_state'])) {
$query->where('ord_state', $search_data['ord_state']);
}
})
->where(function ($query) use ($search_data) {
// 订单完成状态4已完成,其他值是未完成
if (!empty($search_data['ord_wor_state'])) {
if ($search_data['ord_wor_state'] == 4) {
$query->where('ord_wor_state', $search_data['ord_wor_state']);
} else {
$query->where('ord_wor_state', '<>', 4);
}
}
})
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['create_time_start']) && !empty($search_data['create_time_end'])) {
$query->whereBetween('ord_create_time', [$search_data['create_time_start'], $search_data['create_time_end'] . ' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['create_time_start'])) {
$query->where('ord_create_time', '>=', $search_data['create_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['create_time_end'])) {
$query->where('ord_create_time', '<=', $search_data['create_time_end'] . ' 23:59:59');
}
}
}
}) //创建时间
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_form_type'])) {
$query->where('ord_form_type', $search_data['ord_form_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_shipment_party'])) {
$query->where('orcl_shipment_party', $search_data['orcl_shipment_party']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_service_shop_id'])) {
$query->where('ord_service_shop_id', $search_data['ord_service_shop_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_client_id'])) {
$query->where('ord_client_id', $search_data['ord_client_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_match_type'])) {
$query->where('orcl_match_type', $search_data['orcl_match_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ware_id'])) {
$query->where('ord_ware_id', $search_data['ware_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_payment_way'])) {
$query->where('ord_payment_way', $search_data['ord_payment_way']);
}
}) //结算方式:1账期2现结
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_match_adm_id'])) {
$query->where('orcl_match_adm_id', $search_data['orcl_match_adm_id']);
}
})//对单人
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['match_time_start']) && !empty($search_data['match_time_end'])) {
$query->whereBetween('orcl_match_time', [$search_data['match_time_start'], $search_data['match_time_end'] . ' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['match_time_start'])) {
$query->where('orcl_match_time', '>=', $search_data['match_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['match_time_end'])) {
$query->where('orcl_match_time', '<=', $search_data['match_time_end'] . ' 23:59:59');
}
}
}
})//对单时间
->select('ord_id', 'ord_order_number', 'adm_name', 'ord_client_id', 'ord_actual_price', 'ord_ware_id', 'ord_create_time', 'ord_service_type', 'orcl_match_type', 'orcl_shipment_party', 'ord_type', 'orcl_name', 'ord_payment_way')
->orderBy('ord_id', $orderby_type)
->limit(1000)
->get()->toArray();
if (!empty($data)) {
// 将对象转化为数组
$data = json_decode(json_encode($data), true);
$ord_client_id = array_column($data, 'ord_client_id');
// 会员零售
$mem = DB::table('member')
->whereIn('mem_id', $ord_client_id)
->pluck('mem_name', 'mem_id');
// 查询客户单位
$channel = DB::table('channel_unit')
->whereIn('chun_id', $ord_client_id)
->pluck('chun_unit_name', 'chun_id');
// 虚拟加盟店
$virtual = DB::table('virtual_shop')
->whereIn('vish_id', $ord_client_id)
->pluck('vish_name', 'vish_id');
$ware_id = array_column($data, 'ord_ware_id');
// 仓库
$ware = DB::table('warehouse')
->whereIn('ware_id', $ware_id)
->pluck('ware_name', 'ware_id');
foreach ($data as $key => $value) {
$dataInfo[$key]['ord_order_number'] = $value['ord_order_number'];
$dataInfo[$key]['adm_name'] = $value['adm_name'];
if ($value['ord_type'] == 1) {
if (empty($mem[$value['ord_client_id']])) {
$dataInfo[$key]['chun_unit_name'] = $value['orcl_name'];
} else {
$dataInfo[$key]['chun_unit_name'] = $mem[$value['ord_client_id']];
}
} elseif ($value['ord_type'] == 2) {
$dataInfo[$key]['chun_unit_name'] = $channel[$value['ord_client_id']];
} elseif ($value['ord_type'] == 3) {
$dataInfo[$key]['chun_unit_name'] = config('apisystem.sd_chan_info')['name'];
} elseif ($value['orcl_shipment_party'] == 4) {
$dataInfo[$key]['chun_unit_name'] = $virtual[$value['ord_client_id']];
}
$dataInfo[$key]['ord_actual_price'] = $value['ord_actual_price'] / 100; //结算金额
if (isset($ware[$value['ord_ware_id']])) {
$dataInfo[$key]['ware_name'] = $ware[$value['ord_ware_id']];
} else {
$dataInfo[$key]['ware_name'] = '';
}
$dataInfo[$key]['ord_create_time'] = $value['ord_create_time'];
// 订单类型
if ($value['ord_service_type'] == '1') {
$dataInfo[$key]['ord_service_type'] = '服务单';
} elseif ($value['ord_service_type'] == '2') {
$dataInfo[$key]['ord_service_type'] = '销售单';
} elseif ($value['ord_service_type'] == '3') {
$dataInfo[$key]['ord_service_type'] = '换货单';
} elseif ($value['ord_service_type'] == '4') {
$dataInfo[$key]['ord_service_type'] = '退货单';
} elseif ($value['ord_service_type'] == '5') {
$dataInfo[$key]['ord_service_type'] = '发货单';
} elseif ($value['ord_service_type'] == '6') {
$dataInfo[$key]['ord_service_type'] = '结清单';
} elseif ($value['ord_service_type'] == '7') {
$dataInfo[$key]['ord_service_type'] = '救援单';
}
// 对单状态
if ($value['orcl_match_type'] == '1') {
$dataInfo[$key]['orcl_match_type'] = '未确认';
} elseif ($value['orcl_match_type'] == '2') {
$dataInfo[$key]['orcl_match_type'] = '已确认';
}
// 结算方式
if ($value['ord_payment_way'] == '1') {
$dataInfo[$key]['ord_payment_way'] = '账期';
} elseif ($value['ord_payment_way'] == '2') {
$dataInfo[$key]['ord_payment_way'] = '现结';
} elseif ($value['ord_payment_way'] == '3') {
$dataInfo[$key]['ord_payment_way'] = '微信';
} elseif ($value['ord_payment_way'] == '4') {
$dataInfo[$key]['ord_payment_way'] = '支付宝';
}
}
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$dataInfo]);
} else {
return response()->json(['code'=> 500, 'msg'=> 'error', 'data'=> '没有符合条件的数据']);
}
}
// 导出
public function export(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$orderby_type = 'desc'; //排序类型,默认倒序查询
// 当查询待接单状态订单时,按正序查询
if (!empty($request['ord_wor_state']) && $request['ord_wor_state'] == 7) {
$orderby_type = 'asc'; //默认排序类型
}
$data = DB::table('order as a')
->leftJoin('order_client as b', 'b.orcl_ord_id', '=', 'a.ord_id')
->leftJoin('admin as as', 'as.adm_id', '=', 'a.ord_create_id')
->where('ord_cid', $user_info->adm_cid)
->where('ord_superior_shop_id', $shop_id)
->where('ord_delete', 1)
->where('ord_collection_bill', 1) //是否代收账单:1正常订单2代收账单
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_order_number'])) {
$query->where('ord_order_number', 'like', '%' . $search_data['ord_order_number'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_channel_unit'])) {
$query->where('orcl_channel_unit', 'like', '%' . $search_data['orcl_channel_unit'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_name'])) {
$query->where('orcl_name', 'like', '%' . $search_data['orcl_name'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_type'])) {
$query->where('ord_type', $search_data['ord_type']);
}
}) //买家类型:1会员零售2客户单位3速电网单
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_service_type'])) {
$query->where('ord_service_type', $search_data['ord_service_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_create_id'])) {
$query->where('a.ord_create_id', $search_data['ord_create_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_state'])) {
$query->where('ord_state', $search_data['ord_state']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_wor_state'])) {
if ($search_data['ord_wor_state'] == 4) {
$query->where('ord_wor_state', $search_data['ord_wor_state']);
} else {
$query->where('ord_wor_state', '<>', 4);
}
}
})
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['create_time_start']) && !empty($search_data['create_time_end'])) {
$query->whereBetween('ord_create_time', [$search_data['create_time_start'], $search_data['create_time_end'] . ' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['create_time_start'])) {
$query->where('ord_create_time', '>=', $search_data['create_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['create_time_end'])) {
$query->where('ord_create_time', '<=', $search_data['create_time_end'] . ' 23:59:59');
}
}
}
}) //创建时间
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_form_type'])) {
$query->where('ord_form_type', $search_data['ord_form_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_shipment_party'])) {
$query->where('orcl_shipment_party', $search_data['orcl_shipment_party']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_service_shop_id'])) {
$query->where('ord_service_shop_id', $search_data['ord_service_shop_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_client_id'])) {
$query->where('ord_client_id', $search_data['ord_client_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_match_type'])) {
$query->where('orcl_match_type', $search_data['orcl_match_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ware_id'])) {
$query->where('ord_ware_id', $search_data['ware_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_payment_way'])) {
$query->where('ord_payment_way', $search_data['ord_payment_way']);
}
}) //结算方式:1账期2现结
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_match_adm_id'])) {
$query->where('orcl_match_adm_id', $search_data['orcl_match_adm_id']);
}
})//对单人
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['match_time_start']) && !empty($search_data['match_time_end'])) {
$query->whereBetween('orcl_match_time', [$search_data['match_time_start'], $search_data['match_time_end'] . ' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['match_time_start'])) {
$query->where('orcl_match_time', '>=', $search_data['match_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['match_time_end'])) {
$query->where('orcl_match_time', '<=', $search_data['match_time_end'] . ' 23:59:59');
}
}
}
})//对单时间
->select('ord_id', 'ord_order_number', 'adm_name', 'ord_client_id', 'ord_actual_price', 'ord_ware_id', 'ord_create_time', 'ord_service_type', 'orcl_match_type', 'orcl_shipment_party', 'ord_type', 'orcl_name', 'ord_payment_way', 'orcl_match_adm_id', 'orcl_match_time')
->orderBy('ord_id', $orderby_type)
->limit(1000)
->get()->toArray();
if (!empty($data)) {
// 将对象转化为数组
$data = json_decode(json_encode($data), true);
$ord_client_id = array_column($data, 'ord_client_id');
// 会员零售
$mem = DB::table('member')
->whereIn('mem_id', $ord_client_id)
->pluck('mem_name', 'mem_id');
// 查询客户单位
$channel = DB::table('channel_unit')
->whereIn('chun_id', $ord_client_id)
->pluck('chun_unit_name', 'chun_id');
// 虚拟加盟店
$virtual = DB::table('virtual_shop')
->whereIn('vish_id', $ord_client_id)
->pluck('vish_name', 'vish_id');
$ware_id = array_column($data, 'ord_ware_id');
// 仓库
$ware = DB::table('warehouse')
->whereIn('ware_id', $ware_id)
->pluck('ware_name', 'ware_id');
// 对单人
$orcl_match_adm_id = array_column($data, 'orcl_match_adm_id');
$admin = DB::table('admin')
->whereIn('adm_id', $orcl_match_adm_id)
->pluck('adm_name', 'adm_id');
foreach ($data as $key => $value) {
if ($value['ord_type'] == 1) {
if (empty($mem[$value['ord_client_id']])) {
$data[$key]['ord_client_id'] = $value['orcl_name'];
} else {
$data[$key]['ord_client_id'] = $mem[$value['ord_client_id']];
}
} elseif ($value['ord_type'] == 2) {
$data[$key]['ord_client_id'] = $channel[$value['ord_client_id']];
} elseif ($value['ord_type'] == 3) {
$data[$key]['ord_client_id'] = config('apisystem.sd_chan_info')['name'];
} elseif ($value['orcl_shipment_party'] == 4) {
$data[$key]['ord_client_id'] = $virtual[$value['ord_client_id']];
}
if (isset($ware[$value['ord_ware_id']])) {
$data[$key]['ord_ware_id'] = $ware[$value['ord_ware_id']];
} else {
$data[$key]['ord_ware_id'] = '';
}
$data[$key]['ord_actual_price'] = $value['ord_actual_price'] / 100; //结算金额
// 对单状态
if ($value['orcl_match_type'] == '1') {
$data[$key]['orcl_match_type'] = '未确认';
} elseif ($value['orcl_match_type'] == '2') {
$data[$key]['orcl_match_type'] = '已确认';
}
// 结算方式
if ($value['ord_payment_way'] == '1') {
$data[$key]['ord_payment_way'] = '账期';
} elseif ($value['ord_payment_way'] == '2') {
$data[$key]['ord_payment_way'] = '现结';
} elseif ($value['ord_payment_way'] == '3') {
$data[$key]['ord_payment_way'] = '微信';
} elseif ($value['ord_payment_way'] == '4') {
$data[$key]['ord_payment_way'] = '支付宝';
}
// 服务类型
if ($value['ord_service_type'] == '1') {
$data[$key]['ord_service_type'] = '服务单';
} elseif ($value['ord_service_type'] == '2') {
$data[$key]['ord_service_type'] = '销售单';
} elseif ($value['ord_service_type'] == '3') {
$data[$key]['ord_service_type'] = '换货单';
} elseif ($value['ord_service_type'] == '4') {
$data[$key]['ord_service_type'] = '退货单';
} elseif ($value['ord_service_type'] == '5') {
$data[$key]['ord_service_type'] = '发货单';
} elseif ($value['ord_service_type'] == '6') {
$data[$key]['ord_service_type'] = '结清单';
} elseif ($value['ord_service_type'] == '7') {
$data[$key]['ord_service_type'] = '救援单';
}
if (isset($admin[$value['orcl_match_adm_id']])) {
$data[$key]['orcl_match_adm_id'] = $admin[$value['orcl_match_adm_id']];
} else {
$data[$key]['orcl_match_adm_id'] = '';
}
unset($data[$key]['ord_id']);
unset($data[$key]['orcl_shipment_party']);
unset($data[$key]['ord_type']);
}
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'没有符合条件的数据']);
}
$pathName = storage_path() . "/app/public/excel"; //获取上传excel路径
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName, 0775, true);
chmod($pathName, 0775);
}
$streamFileRand = '对单列表' . time() . rand(1000, 9999) . '.xls';
// 产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
$streamFilename = $pathName . '/' . $streamFileRand;
$where['action_name'] = '对单列表';
$where['field_name'] = ['订单编号', '开单人', '客户单位', '结算金额', '仓库名称', '开单时间', '订单类型', '对单状态', '姓名', '结算方式', '对单人', '对单时间'];
// 调用导出的公共方法
export::publicExport(
$streamFilename, //路径
$where, //sheet名及其每一行的标题
$data //导出数据
);
// 判断文件是否存在 存在则成功 不存在则失败
if (file_exists($streamFilename)) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'storage/excel/' . $streamFileRand]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'导出失败']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Models\Api\Common;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
class NetSingleController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('order as a')
->leftJoin('order_client as b', 'b.orcl_ord_id', '=', 'a.ord_id')
->leftJoin('admin as c', 'c.adm_id', '=', 'a.ord_create_id')
->where('ord_cid', $user_info->adm_cid)
->where('ord_superior_shop_id', $shop_id)
->where('ord_delete', 1)
->where('ord_collection_bill', 1) //是否代收账单:1正常订单2代收账单
->where('ord_type', 3)
->where(function ($query) use ($search_data) {
if (!empty($search_data['adm_name'])) {
$query->where('c.adm_name', 'like', '%'.$search_data['adm_name'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_order_number'])) {
$query->where('ord_order_number', 'like', '%'.$search_data['ord_order_number'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_channel_unit'])) {
$query->where('orcl_channel_unit', 'like', '%'.$search_data['orcl_channel_unit'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_name'])) {
$query->where('orcl_name', 'like', '%'.$search_data['orcl_name'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_phone'])) {
$query->where('orcl_phone', 'like', '%'.$search_data['orcl_phone'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_car_num'])) {
$query->where('orcl_car_num', 'like', '%'.$search_data['orcl_car_num'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_type'])) {
$query->where('ord_type', $search_data['ord_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_service_type'])) {
$query->where('ord_service_type', $search_data['ord_service_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_create_id'])) {
$query->where('a.ord_create_id', $search_data['ord_create_id']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_state'])) {
$query->where('ord_state', $search_data['ord_state']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_wor_state'])) {
$query->where('ord_wor_state', $search_data['ord_wor_state']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_payment_way'])) {
$query->where('ord_payment_way', $search_data['ord_payment_way']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_remark'])) {
$query->where('ord_remark', 'like', '%'.$search_data['ord_remark'].'%');
}
}) //备注
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_orla_id'])) {
$query->where('ord_orla_id', $search_data['ord_orla_id']);
}
}) //订单标签
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['create_time_start']) && !empty($search_data['create_time_end'])) {
$query->whereBetween('ord_create_time', [$search_data['create_time_start'], $search_data['create_time_end'].' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['create_time_start'])) {
$query->where('ord_create_time', '>=', $search_data['create_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['create_time_end'])) {
$query->where('ord_create_time', '<=', $search_data['create_time_end'].' 23:59:59');
}
}
}
}) //创建时间
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_order_type'])) {
$query->where('orcl_order_type', $search_data['orcl_order_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['orcl_order_type'])) {
$query->where('orcl_order_type', $search_data['orcl_order_type']);
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['ord_other_system_number'])) {
$query->where('ord_other_system_number', 'like', '%'.$search_data['ord_other_system_number'].'%');
}
})
->select('ord_id', 'adm_name', 'ord_order_number', 'ord_goods_quantity', 'ord_actual_price', 'ord_payment_way', 'ord_state', 'ord_wor_state', 'ord_wor_quantity', 'ord_type', 'ord_service_type', 'orcl_channel_unit', 'orcl_name', 'orcl_phone', 'orcl_car_num', 'orcl_province', 'orcl_city', 'orcl_county', 'orcl_address', 'ord_remark', 'ord_create_time', 'ord_order_price', 'ord_delete', 'ord_collection_price', 'ord_orla_id', 'ord_plus_minus', 'ord_service_shop_id', 'ord_acti_id', 'ord_acti_row', 'orcl_order_type', 'orcl_consent_state', 'orcl_consent_type', 'orcl_reminder_state', 'ord_order_state', 'ord_other_system_number')
->orderBy('ord_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
$ord_id = array_column($list_items, 'ord_id');//订单id
$ord_orla_id = array_unique(array_column($list_items, 'ord_orla_id'));//订单标签id
$ord_service_shop_id = array_unique(array_column($list_items, 'ord_service_shop_id'));//服务门店id
$ord_acti_id = array_unique(array_column($list_items, 'ord_acti_id'));//活动id
$ord_acti_row = array_unique(array_column($list_items, 'ord_acti_row'));//活动id
// 查询商品信息
$order_goods = DB::table('order_goods')
->whereIn('orgo_ord_id', $ord_id)
->where('orgo_state', '!=', 2)
->select('orgo_ord_id', 'orgo_goo_id', 'orgo_goo_name', 'orgo_goo_goods_encode', 'orgo_goo_price', 'orgo_goo_quantity', 'orgo_is_recycle', 'orgo_collection_price', 'orgo_state', 'orgo_can_assign_quantity', 'orgo_goo_type', 'orgo_recycle_price', 'orgo_recycle_quantity', 'orgo_tem_goo_name as tem_goo_name')
->get();
// 查找操作记录
$order_log = DB::table('order_log')
->whereIn('orlo_ord_id', $ord_id)
->orderBy('orlo_id', 'desc')
->select('orlo_ord_id', 'orlo_time', 'orlo_create_adm_name', 'orlo_content')
->get();
// 查找所有订单回收金额
$recycle_price = DB::table('junk_recycle')
->whereIn('jur_ord_id', $ord_id)
->where('jur_price', '!=', 0)
->select(DB::raw('jur_ord_id,jur_price'))
->get();
// 查找订单标签
$order_label = DB::table('order_label')
->whereIn('orla_id', $ord_orla_id)
->select('orla_id', 'orla_name')
->get();
// 查找服务门店id
$shop_name = DB::table('shop')
->whereIn('shop_id', $ord_service_shop_id)
->select('shop_id', 'shop_store_name', 'shop_type')
->get();
// 查找活动名称
$acti_name = DB::table('activity')
->whereIn('acti_id', $ord_acti_id)
->select('acti_id', 'acti_name', 'acti_activity_type')
->get()->toArray();
$acti_id_data = array_column($acti_name, null, 'acti_id');
foreach ($list_items as $key => $value) {
if ($value->ord_acti_id) {
if ($acti_id_data[$value->ord_acti_id]->acti_activity_type == '1') {//折扣
$data_info['find_acdi'][$value->ord_id] = DB::table('activity_discount as acdi')
->where('acdi_acti_id', $value->ord_acti_id)
->where('acdi_row', $value->ord_acti_row)
->select('acdi_acti_id', 'acdi_discount', 'acdi_row')
->first();
} elseif ($acti_id_data[$value->ord_acti_id]->acti_activity_type == '2') {// 买送
$data_info['find_acdo'][$value->ord_id] = DB::table('activity_donate')
->where('acdo_acti_id', $value->ord_acti_id)
->where('acdo_row', $value->ord_acti_row)
->select('acdo_acti_id', 'acdo_purchase_quantity', 'acdo_attached_quantity', 'acdo_row')
->first();
} elseif ($acti_id_data[$value->ord_acti_id]->acti_activity_type == '3') {// 买赠
$data_info['find_acdos'][$value->ord_id] = DB::table('activity_donate')
->where('acdo_acti_id', $value->ord_acti_id)
->where('acdo_row', $value->ord_acti_row)
->select('acdo_acti_id', 'acdo_purchase_quantity', 'acdo_attached_quantity', 'acdo_row')
->first();
} elseif ($acti_id_data[$value->ord_acti_id]->acti_activity_type == '4') {// 满减
$data_info['find_acdr'][$value->ord_id] = DB::table('activity_discount_reduction')
->where('acdr_acti_id', $value->ord_acti_id)
->where('acdr_row', $value->ord_acti_row)
->select('acdr_acti_id', 'acdr_reduction_price', 'acdr_credit_price', 'acdr_row')
->first();
} elseif ($acti_id_data[$value->ord_acti_id]->acti_activity_type == '5') {// 现结折扣
$data_info['find_acdrs'][$value->ord_id] = DB::table('activity_discount_reduction')
->where('acdr_acti_id', $value->ord_acti_id)
->where('acdr_row', $value->ord_acti_row)
->select('acdr_acti_id', 'acdr_reduction_price', 'acdr_discount', 'acdr_row')
->first();
} elseif ($acti_id_data[$value->ord_acti_id]->acti_activity_type == '8') {// 大批量采购
$data_info['find_acpr'][$value->ord_id] = DB::table('activity_procurement')
->where('acpr_acti_id', $value->ord_acti_id)
->where('acpr_row', $value->ord_acti_row)
->select('acpr_acti_id', 'acpr_recycle_quantity', 'acpr_row', 'acpr_goods_quantity')
->first();
}
}
if ($value->ord_wor_state == '7') {
$list_items[$key]->orcl_name = substr_replace($list_items[$key]->orcl_name, '****', 3, 10);
$list_items[$key]->orcl_phone = substr_replace($list_items[$key]->orcl_phone, '****', 3, 8);
;
$list_items[$key]->orcl_city = '***';
$list_items[$key]->orcl_county = '***';
$list_items[$key]->orcl_address = '***';
}
}
} else {
$order_goods = [];
$order_log = [];
$recycle_price = 0;
$order_label = [];
$shop_name = [];
$acti_name = [];
}
$state_count = DB::table('order')
->where('ord_cid', $user_info->adm_cid)
->where('ord_superior_shop_id', $shop_id)
->where('ord_delete', 1)
->where('ord_type', 3)
->select(DB::raw('count(*) as count, ord_wor_state'))
->groupBy('ord_wor_state')
->get();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['order_goods'] = $order_goods; //订单商品数据
$data_info['state_count'] = $state_count;
$data_info['recycle_price'] = $recycle_price; //订单回收金额
$data_info['order_log'] = $order_log; //操作记录
$data_info['order_label'] = $order_label; //订单标签
$data_info['shop_name'] = $shop_name; //门店名称
$data_info['acti_name'] = $acti_name; //活动名称
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if ($list_data) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'暂无数据']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Models\Api\Common;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyNoteMessageController;
// 财务系统 -- 短信日志列表
class NoteMessageController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyNoteMessageController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$search_data = $request->all();
$list_data = DB::table('send_message')
->where('seme_cid', $user_info->adm_cid)
->where('seme_shop_id', $user_info->adm_shop_id)
->where(function ($query) use ($search_data) {
if (!empty($search_data['seme_name'])) {
$query->where('seme_name', 'like', '%'.$search_data['seme_name'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['seme_phone'])) {
$query->where('seme_phone', 'like', '%'.$search_data['seme_phone'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['seme_state'])) {
$query->where('seme_state', $search_data['seme_state']);
}
})
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['create_time_start']) && !empty($search_data['create_time_end'])) {
$query->whereBetween('seme_create_time', [$search_data['create_time_start'], $search_data['create_time_end'].' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['create_time_start'])) {
$query->where('seme_create_time', '>=', $search_data['create_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['create_time_end'])) {
$query->where('seme_create_time', '<=', $search_data['create_time_end'].' 23:59:59');
}
}
}
}) //创建时间
->select('seme_id', 'seme_name', 'seme_phone', 'seme_content', 'seme_row', 'seme_state', 'seme_create_time')
->orderBy('seme_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
$count_row = DB::table('send_message')
->where('seme_cid', $user_info->adm_cid)
->where('seme_shop_id', $user_info->adm_shop_id)
->where(function ($query) use ($search_data) {
if (!empty($search_data['seme_name'])) {
$query->where('seme_name', 'like', '%'.$search_data['seme_name'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['seme_phone'])) {
$query->where('seme_phone', 'like', '%'.$search_data['seme_phone'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['seme_state'])) {
$query->where('seme_state', $search_data['seme_state']);
}
})
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['create_time_start']) && !empty($search_data['create_time_end'])) {
$query->whereBetween('seme_create_time', [$search_data['create_time_start'], $search_data['create_time_end'].' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['create_time_start'])) {
$query->where('seme_create_time', '>=', $search_data['create_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['create_time_end'])) {
$query->where('seme_create_time', '<=', $search_data['create_time_end'].' 23:59:59');
}
}
}
}) //创建时间
->where('seme_state', 1)
->select(DB::raw('sum(seme_row) as seme_row'))
->first();
$shin_residue_num = DB::table('shop_info')
->where('shin_shop_id',$user_info->adm_shop_id)
->value('shin_residue_num');
$shin_residue_num = $shin_residue_num ?: 0;
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['seme_row'] = $count_row->seme_row; //总条数
$data_info['shin_residue_num'] = $shin_residue_num; //剩余总条数
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if ($list_data) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'暂无数据']);
}
}
// 模板列表
public function listTemplate(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('send_template')
->where('sete_cid', $user_info->adm_cid)
->where('sete_superior_shop_id', $shop_id)
->where(function ($query) use ($search_data) {
if (!empty($search_data['sete_name'])) {
$query->where('sete_name', 'like', '%'.$search_data['sete_name'].'%');
}
})
->select('sete_id', 'sete_name', 'sete_content', 'sete_sign', 'sete_number')
->orderBy('sete_id', 'desc')
->get();
if ($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$list_data]);
} else {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 添加模板
public function addTemplate(Request $request)
{
// 验证数据
$verify_data = new VerifyNoteMessageController;
$error_message = $verify_data->addTemplateValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$sete_id = DB::table('send_template')
->where('sete_name', $request['sete_name'])
->value('sete_id');
if (!empty($sete_id)) {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'模板名称已存在']);
}
$sete['sete_cid'] = $user_info->adm_cid;
$sete['sete_shop_id'] = $user_info->adm_shop_id;
$sete['sete_superior_shop_id'] = $shop_id;
$sete['sete_name'] = $request['sete_name'];//模板名称
$sete['sete_sign'] = $request['sete_sign'];//模板签名
$sete['sete_content'] = $request['sete_content'];//模板内容
$sete['sete_number'] = $request['sete_number'];//模板所占用的短信数量
$res = DB::table('send_template')->insert($sete);
if ($res) {
Common::addLog($user_info, getRealIp($request), '短信列表', '模板设置', '添加短信模板:'.$sete['sete_name']);
return response()->json(['code'=> 200,'msg'=>'success','data'=>'添加成功']);
} else {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'编辑失败']);
}
}
// 编辑模板
public function editTemplate(Request $request)
{
// 验证数据
$verify_data = new VerifyNoteMessageController;
$error_message = $verify_data->editTemplateValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$sete_id = DB::table('send_template')
->where('sete_id', '!=', $request['sete_id'])
->where('sete_name', $request['sete_name'])
->value('sete_id');
if (!empty($sete_id)) {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'模板名称已存在']);
}
$sete['sete_name'] = $request['sete_name'];//模板名称
$sete['sete_sign'] = $request['sete_sign'];//模板签名
$sete['sete_content'] = $request['sete_content'];//模板内容
$sete['sete_number'] = $request['sete_number'];//模板所占用的短信数量
$sete['sete_update_time'] = date('Y-m-d H:i:s');//模板所占用的短信数量
$res = DB::table('send_template')
->where('sete_id', $request['sete_id'])
->update($sete);
if ($res) {
Common::addLog($user_info, getRealIp($request), '短信列表', '模板设置', '编辑短信模板:'.$sete['sete_name']);
return response()->json(['code'=> 200,'msg'=>'success','data'=>'编辑成功']);
} else {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'编辑失败']);
}
}
// 短信模块
public function listModule(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('send_module')
->leftjoin('send_template as st', 'st.sete_id', '=', 'mode_sete_id')
->where('mode_cid', $user_info->adm_cid)
->where('mode_superior_shop_id', $shop_id)
->where(function ($query) use ($search_data) {
if (!empty($search_data['mode_name'])) {
$query->where('mode_name', 'like', '%'.$search_data['mode_name'].'%');
}
})
->select('mode_id', 'mode_name', 'mode_state', 'sete_name')
->orderBy('mode_id', 'desc')
->get();
if ($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$list_data]);
} else {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 绑定
public function binding(Request $request)
{
// 验证数据
$verify_data = new VerifyNoteMessageController;
$error_message = $verify_data->bindingValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$res = DB::table('send_module')
->where('mode_id', $request['mode_id'])
->update(['mode_sete_id'=>$request['sete_id'],'mode_update_time'=>date('Y-m-d H:i:s')]);
if ($res) {
$mode_name = DB::table('send_module')
->where('mode_id', $request['mode_id'])
->value('mode_name');
$sete_name = DB::table('send_template')
->where('sete_id', $request['sete_id'])
->value('sete_name');
Common::addLog($user_info, getRealIp($request), '短信列表', '模板设置', '模块:'.$mode_name.' 绑定了短信模板:'.$sete_name);
return response()->json(['code'=> 200,'msg'=>'success','data'=>'绑定成功']);
} else {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'绑定失败']);
}
}
// 模块停用
public function stopModule(Request $request)
{
// 验证数据
$verify_data = new VerifyNoteMessageController;
$error_message = $verify_data->stopModuleValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$mode_name = DB::table('send_module')
->where('mode_id', $request['mode_id'])
->value('mode_name');
$res = DB::table('send_module')
->where('mode_id', $request['mode_id'])
->update(['mode_state'=>2,'mode_update_time'=>date('Y-m-d H:i:s')]);
if ($res) {
Common::addLog($user_info, getRealIp($request), '短信列表', '模块设置', '模块:'.$mode_name.'停用');
return response()->json(['code'=> 200,'msg'=>'success','data'=>'停用成功']);
} else {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'停用失败']);
}
}
// 模块启用
public function startModule(Request $request)
{
// 验证数据
$verify_data = new VerifyNoteMessageController;
$error_message = $verify_data->startModuleValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$mode_name = DB::table('send_module')
->where('mode_id', $request['mode_id'])
->value('mode_name');
$res = DB::table('send_module')
->where('mode_id', $request['mode_id'])
->update(['mode_state'=>1,'mode_update_time'=>date('Y-m-d H:i:s')]);
if ($res) {
Common::addLog($user_info, getRealIp($request), '短信列表', '模块设置', '模块:'.$mode_name.'启用');
return response()->json(['code'=> 200,'msg'=>'success','data'=>'启用成功']);
} else {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'启用失败']);
}
}
// 删除模板
public function deleteTemplate(Request $request)
{
// 验证数据
$verify_data = new VerifyNoteMessageController;
$error_message = $verify_data->deleteTemplateValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断模块是否引用
$mode_id = DB::table('send_module')
->where('mode_sete_id', $request['sete_id'])
->value('mode_id');
if ($mode_id) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'当前模板已被绑定,无法删除']);
}
$sete_name = DB::table('send_template')
->where('sete_id', $request['sete_id'])
->value('sete_name');
$res = DB::table('send_template')
->where('sete_id', $request['sete_id'])
->delete();
if ($res) {
Common::addLog($user_info, getRealIp($request), '短信列表', '删除', '模块:'.$sete_name.'删除成功');
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'删除成功']);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'删除失败']);
}
}
//支付记录
public function listPay(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('send_pay_record as spr')
->leftjoin('admin as a','a.adm_id','=','spr.sepr_adm_id')
->where('sepr_cid', $user_info->adm_cid)
->where('sepr_superior_shop_id', $shop_id)
->where(function ($query) use ($search_data) {
if (!empty($search_data['sete_name'])) {
$query->where('sete_name', 'like', '%'.$search_data['sete_name'].'%');
}
})
->select('adm_name', 'sepr_send_number', 'sepr_money', 'sepr_num', 'sepr_create_time','sepr_state')
->orderBy('sepr_id', 'desc')
->get();
if ($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$list_data]);
} else {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyPaymentBillController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
use App\Http\Models\Api\ReceivableBill;
use App\Http\Models\Api\AccountingSettlement;
class PaymentBillController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyPaymentBillController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$search_data = $request->all();
if(!empty($search_data['acpa_original_number']) || !empty($search_data['chun_unit_name']) || !empty($search_data['acpa_acti_id']) | !empty($search_data['acpa_settle_id']) || !empty($search_data['acpa_type']) || !empty($search_data['acpa_chty_id']) || !empty($search_data['chun_phone']) || !empty($search_data['acpa_remark']) || !empty($search_data['start_time']) || !empty($search_data['end_time'])){
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$list_data = DB::table('accounts_payable as p')
->leftJoin('channel_unit as u', 'p.acpa_client_id', '=', 'u.chun_id')
->where('acpa_cid',$user_info->adm_cid)
->where('acpa_shop_superior_id',$shop_id)
->where('acpa_state',1) //只查询出未核销的
->where('acpa_belongs_id','=',0)
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_original_number'])) {
$query->where('acpa_original_number', 'like', '%'.$search_data['acpa_original_number'].'%' );
}
}) //单号
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_type'])) {
$query->where('acpa_type', $search_data['acpa_type'] );
}
}) //单据类型 1.预付款 2.采购账单
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_chty_id'])) {
$query->where('acpa_chty_id', $search_data['acpa_chty_id'] );
}
}) //单位类型
->where(function($query) use($search_data) {
if (!empty($search_data['chun_unit_name'])) {
$query->where('chun_unit_name', 'like', '%'.$search_data['chun_unit_name'].'%' );
}
}) //单位名称
->where(function($query) use($search_data) {
if (!empty($search_data['chun_phone'])) {
$query->where('chun_phone', 'like', '%'.$search_data['chun_phone'].'%' );
}
}) //客户电话
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])){
$query->whereBetween('acpa_settle_time',[$search_data['start_time'],$search_data['end_time'].' 23:59:59']);
}else{
// 如果选择开始时间
if (!empty($search_data['start_time'])){
$query->where('acpa_settle_time','>=',$search_data['start_time']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('acpa_settle_time','<=',$search_data['end_time'].' 23:59:59');
}
}
}
}) //结款时间
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_settle_id'])) {
$query->where('acpa_settle_id', $search_data['acpa_settle_id']);
}
}) //结款人
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_acti_id'])) {
$query->where('acpa_acti_id', $search_data['acpa_acti_id']);
}
}) //会计科目
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_remark'])) {
$query->where('acpa_remark', 'like', '%'.$search_data['acpa_remark'].'%');
}
}) //备注
->select('acpa_id', 'acpa_original_number', 'acpa_type', 'chun_unit_name', 'acpa_settle_price',
'acpa_settle_time', 'acpa_acti_id', 'acpa_actual_price', 'acpa_state', 'acpa_settle_id',
'chun_name', 'chun_phone', 'acpa_chty_id', 'acpa_remark','acpa_create_time','acpa_yet_receipt','acpa_original_id','acpa_number_id','acpa_zero_price','acpa_plus_minus')
->orderBy('acpa_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
foreach ($list_items as $key => $value) {
$settle_id[] = $value->acpa_settle_id; //结款人id
$acti_id[] = $value->acpa_acti_id; //科目管理id
$chty_id[] = $value->acpa_chty_id; //单位类型id
if(empty($value->acpa_number_id)){
$list_items[$key]->acpa_original_id = 0;
}
unset($list_items[$key]->acpa_number_id);
}
$positive = DB::table('accounts_payable as p')
->leftJoin('channel_unit as u', 'p.acpa_client_id', '=', 'u.chun_id')
->where('acpa_cid',$user_info->adm_cid)
->where('acpa_shop_superior_id',$shop_id)
->where('acpa_state',1) //只查询出未核销的
->where('acpa_statistics_type',1)
->where('acpa_plus_minus',1)//金额正值
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_original_number'])) {
$query->where('acpa_original_number', 'like', '%'.$search_data['acpa_original_number'].'%' );
}
}) //单号
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_type'])) {
$query->where('acpa_type', $search_data['acpa_type'] );
}
}) //单据类型 1.预付款 2.采购账单
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_chty_id'])) {
$query->where('acpa_chty_id', $search_data['acpa_chty_id'] );
}
}) //单位类型
->where(function($query) use($search_data) {
if (!empty($search_data['chun_unit_name'])) {
$query->where('chun_unit_name', 'like', '%'.$search_data['chun_unit_name'].'%' );
}
}) //单位名称
->where(function($query) use($search_data) {
if (!empty($search_data['chun_phone'])) {
$query->where('chun_phone', 'like', '%'.$search_data['chun_phone'].'%' );
}
}) //客户电话
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])){
$query->whereBetween('acpa_settle_time',[$search_data['start_time'],$search_data['end_time'].' 23:59:59']);
}else{
// 如果选择开始时间
if (!empty($search_data['start_time'])){
$query->where('acpa_settle_time','>=',$search_data['start_time']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('acpa_settle_time','<=',$search_data['end_time'].' 23:59:59');
}
}
}
}) //结款时间
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_settle_id'])) {
$query->where('acpa_settle_id', $search_data['acpa_settle_id']);
}
}) //结款人
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_acti_id'])) {
$query->where('acpa_acti_id', $search_data['acpa_acti_id']);
}
}) //会计科目
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_remark'])) {
$query->where('acpa_remark', 'like', '%'.$search_data['acpa_remark'].'%');
}
}) //备注
->select(DB::raw('sum(acpa_settle_price) as acpa_settle_price,sum(acpa_actual_price) as acpa_actual_price,sum(acpa_yet_receipt) as acpa_yet_receipt,sum(acpa_zero_price) as acpa_zero_price'))
->first();
$minus = DB::table('accounts_payable as p')
->leftJoin('channel_unit as u', 'p.acpa_client_id', '=', 'u.chun_id')
->where('acpa_cid',$user_info->adm_cid)
->where('acpa_shop_superior_id',$shop_id)
->where('acpa_state',1) //只查询出未核销的
->where('acpa_statistics_type',1)
->where('acpa_plus_minus',2)//金额正值
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_original_number'])) {
$query->where('acpa_original_number', 'like', '%'.$search_data['acpa_original_number'].'%' );
}
}) //单号
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_type'])) {
$query->where('acpa_type', $search_data['acpa_type'] );
}
}) //单据类型 1.预付款 2.采购账单
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_chty_id'])) {
$query->where('acpa_chty_id', $search_data['acpa_chty_id'] );
}
}) //单位类型
->where(function($query) use($search_data) {
if (!empty($search_data['chun_unit_name'])) {
$query->where('chun_unit_name', 'like', '%'.$search_data['chun_unit_name'].'%' );
}
}) //单位名称
->where(function($query) use($search_data) {
if (!empty($search_data['chun_phone'])) {
$query->where('chun_phone', 'like', '%'.$search_data['chun_phone'].'%' );
}
}) //客户电话
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])){
$query->whereBetween('acpa_settle_time',[$search_data['start_time'],$search_data['end_time'].' 23:59:59']);
}else{
// 如果选择开始时间
if (!empty($search_data['start_time'])){
$query->where('acpa_settle_time','>=',$search_data['start_time']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('acpa_settle_time','<=',$search_data['end_time'].' 23:59:59');
}
}
}
}) //结款时间
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_settle_id'])) {
$query->where('acpa_settle_id', $search_data['acpa_settle_id']);
}
}) //结款人
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_acti_id'])) {
$query->where('acpa_acti_id', $search_data['acpa_acti_id']);
}
}) //会计科目
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_remark'])) {
$query->where('acpa_remark', 'like', '%'.$search_data['acpa_remark'].'%');
}
}) //备注
->select(DB::raw('sum(acpa_settle_price) as acpa_settle_price,sum(acpa_actual_price) as acpa_actual_price,sum(acpa_yet_receipt) as acpa_yet_receipt,sum(acpa_zero_price) as acpa_zero_price'))
->first();
$acpa_settle_price = $positive->acpa_settle_price - $minus->acpa_settle_price;//实际金额
$acpa_yet_receipt = $positive->acpa_yet_receipt - $minus->acpa_yet_receipt;//已收金额
$acpa_zero_price = $positive->acpa_zero_price - $minus->acpa_zero_price;//抹零金额
// $actual_price = $positive->acpa_actual_price - $minus->acpa_actual_price;//结算金额
// 欠收 = 结算金额 - 已收 - 抹零
$bad_crop = ($acpa_settle_price - $acpa_yet_receipt - $acpa_zero_price) / 100;
// 查找结款人
$adm_info = DB::table('admin')
->whereIn('adm_id',$settle_id)
->get(['adm_id','adm_name']);
// 查找会计科目
$account_info = DB::table('account_title')
->whereIn('acti_id',$acti_id)
->get(['acti_id','acti_course_title']);
// 查找单位类型
$type_info = DB::table('channel_type')
->whereIn('chty_id',$chty_id)
->get(['chty_id','chty_name']);
}else{
$adm_info = [];
$account_info = [];
$type_info = [];
$bad_crop = 0;
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['adm_info'] = $adm_info; //结款人数据
$data_info['account_info'] = $account_info; //会计科目数据
$data_info['type_info'] = $type_info; //单位类型数据
$data_info['bad_crop_price'] = $bad_crop; //统计金额
}else{
$data_info['data'] = [];
}
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}
// 预付款
public function paymentMoney(Request $request)
{
// 验证数据
$verify_data = new VerifyPaymentBillController;
$error_message = $verify_data->paymentMoneyValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
if($request['type'] == 1){
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>'YFK'.rand(10,99).time().rand(10000,99999)]);
}
if (empty($request['acpa_actual_price'])) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'金额不能为0!']);
}
// 当前科目的期末余额
$acti_closing_account = DB::table('account_title')
->where('acti_id',$request['acpa_acti_id'])
->value('acti_closing_account');
if ($request['acpa_actual_price'] * 100 > $acti_closing_account) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'当前科目余额不足,无法创建预付款!']);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
DB::beginTransaction();
// 生成应付账单
$createBill = ReceivableBill::addAccounts(
$user_info, //用户信息
1, //类型:1.预付款 2.采购账单
0, //应收账款id
0, //原始id(无)
$request['acpa_original_number'], //应收账款单号/原始号(账单编号)
2, //客户类型:1.门店零售 2.来往单位
$request['acpa_client_id'], //会员id/来往单位id
$request['acpa_client_name'], //来往单位名称
$request['acpa_actual_price'] * 100, //结算金额
$request['acpa_settle_time'], //结款时间
$request['acpa_acti_id'], //会计科目id
$request['acpa_actual_price'] * 100, //实际金额
0, //抹零金额
1, //状态:1.未核销 2.已核销
1, //应收账单id是否是自己 1.不是 2.是
'', //备注
0 //已收金额
);
// 添加结款明细记录
$acset_res = AccountingSettlement::add(
$user_info, // [用户信息]
8, // 单据类型1订单结算2订单账单3工单账单4采购账单5销售账单6预收款7采购入库单现金8预付款9订单代收
$createBill, // [与单据类型对应的id]
$request['acpa_original_number'], // [与单据类型对应的单号]
2, // [买家类型1门店零售2来往单位]
$request['acpa_client_id'], // [会员/客户id]
$request['acpa_client_name'], // [来往单位名称]
$request['acpa_acti_id'], // [会计科目id]
2, // [类型1收入2支出]
$request['acpa_actual_price'] * 100,// [实际金额](此次的实收金额)
0, // [合计金额](此次的应收金额)
0, // [欠收金额](此次结款后还应收金额)
0, // [抹零金额]
'' // [备注]
);
if($createBill && $acset_res){
Common::addLog($user_info, getRealIp($request), '应付账款','预付款',$request['acpa_original_number'].'预收款新建成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'新建预付款成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'新建预付款失败']);
}
}
// 付款记录详情
public function details(Request $request)
{
// 验证数据
$verify_data = new VerifyPaymentBillController;
$error_message = $verify_data->detailsValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$payable_data = DB::table('accounts_payable')
->where('acpa_id',$request['acpa_id'])
->first(['acpa_create_time', 'acpa_original_number', 'acpa_type', 'acpa_client_name', 'acpa_settle_price',
'acpa_actual_price', 'acpa_yet_receipt', 'acpa_zero_price',
'acpa_plus_minus', 'acpa_original_id']);
if(empty($payable_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前应付账款不存在']);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 预付款详情
if($request['type'] == 1){
$find_data = DB::table('accounts_details as d')
->leftJoin('accounts_payable as p', 'p.acpa_id', '=', 'd.acde_advance_id')
->where('acpa_id',$request['acpa_id'])
->get(['acde_acset_id']);
$find_data = json_decode(json_encode($find_data),true);
$acde_acset_id = array_column($find_data, 'acde_acset_id');
$record_data = DB::table('accounting_settlement as a')
->leftJoin('admin as b', 'b.adm_id', '=', 'a.acset_adm_id')
->leftJoin('account_title as c', 'c.acti_id', '=', 'a.acset_acti_id')
->where('acset_adm_cid', $user_info->adm_cid)
->where('acset_superior_shop_id', $shop_id)
->whereIn('acset_id', $acde_acset_id)
->get(['acset_number', 'acset_original_number', 'acset_payment_type','acset_state',
'adm_name', 'acset_actual_price', 'acset_create_time', 'acset_with_time', 'acti_course_title']);
}else{
switch ($payable_data->acpa_type) {
case 1://1预付款
$acset_type = 8;
break;
case 2:// 2采购账单
$acset_type = 4;
break;
}
// 账单收款记录
$record_data = DB::table('accounting_settlement as a')
->leftJoin('admin as b', 'b.adm_id', '=', 'a.acset_adm_id')
->leftJoin('account_title as c', 'c.acti_id', '=', 'a.acset_acti_id')
->where('acset_adm_cid', $user_info->adm_cid)
->where('acset_superior_shop_id', $shop_id)
->where('acset_type', $acset_type)// 单据类型1订单结算2订单账单3工单账单4采购账单5销售账单6预收款7采购入库单现金8预付款
->where('acset_original_id', $payable_data->acpa_original_id)
->get(['acset_number', 'acset_original_number', 'acset_payment_type','acset_state',
'adm_name', 'acset_actual_price', 'acset_create_time', 'acset_with_time', 'acti_course_title']);
}
$data['record_data'] = $record_data;
$data['payable_data'] = $payable_data;
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data]);
}
// 查看详情页面
public function particulars(Request $request)
{
// 验证数据
$verify_data = new VerifyPaymentBillController;
$error_message = $verify_data->particularsValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$search_data = $request->all();
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$list_data = DB::table('accounts_payable as p')
->leftJoin('channel_unit as u', 'p.acpa_client_id', '=', 'u.chun_id')
->where('acpa_cid',$user_info->adm_cid)
->where('acpa_shop_superior_id',$shop_id)
->where('acpa_state',1) //只查询出未核销的
->where('acpa_belongs_id',$search_data['acpa_original_id'])
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_original_number'])) {
$query->where('acpa_original_number', 'like', '%'.$search_data['acpa_original_number'].'%' );
}
}) //单号
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_chty_id'])) {
$query->where('acpa_chty_id', $search_data['acpa_chty_id'] );
}
}) //单位类型
->where(function($query) use($search_data) {
if (!empty($search_data['chun_unit_name'])) {
$query->where('chun_unit_name', 'like', '%'.$search_data['chun_unit_name'].'%' );
}
}) //单位名称
->where(function($query) use($search_data) {
if (!empty($search_data['chun_phone'])) {
$query->where('chun_phone', 'like', '%'.$search_data['chun_phone'].'%' );
}
}) //客户电话
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])){
$query->whereBetween('acpa_settle_time',[$search_data['start_time'],$search_data['end_time'].' 23:59:59']);
}else{
// 如果选择开始时间
if (!empty($search_data['start_time'])){
$query->where('acpa_settle_time','>=',$search_data['start_time']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('acpa_settle_time','<=',$search_data['end_time'].' 23:59:59');
}
}
}
}) //结款时间
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_settle_id'])) {
$query->where('acpa_settle_id', $search_data['acpa_settle_id']);
}
}) //结款人
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_acti_id'])) {
$query->where('acpa_acti_id', $search_data['acpa_acti_id']);
}
}) //会计科目
->where(function($query) use($search_data) {
if (!empty($search_data['acpa_remark'])) {
$query->where('acpa_remark', 'like', '%'.$search_data['acpa_remark'].'%');
}
}) //备注
->select('acpa_id', 'acpa_original_number', 'acpa_type', 'chun_unit_name', 'acpa_settle_price',
'acpa_settle_time', 'acpa_acti_id', 'acpa_actual_price', 'acpa_state', 'acpa_settle_id',
'chun_name', 'chun_phone', 'acpa_chty_id', 'acpa_remark','acpa_create_time','acpa_yet_receipt')
->orderBy('acpa_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
foreach ($list_items as $key => $value) {
$settle_id[] = $value->acpa_settle_id; //结款人id
$acti_id[] = $value->acpa_acti_id; //科目管理id
$chty_id[] = $value->acpa_chty_id; //单位类型id
if(empty($value->acpa_number_id)){
$list_items[$key]->acpa_original_id = 0;
}
unset($list_items[$key]->acpa_number_id);
}
// 查找结款人
$adm_info = DB::table('admin')
->whereIn('adm_id',$settle_id)
->get(['adm_id','adm_name']);
// 查找会计科目
$account_info = DB::table('account_title')
->whereIn('acti_id',$acti_id)
->get(['acti_id','acti_course_title']);
}else{
$adm_info = [];
$account_info = [];
}
$total_data = DB::table('accounts_payable')
->where('acpa_id',$request['acpa_id'])
->select('acpa_settle_price','acpa_actual_price','acpa_yet_receipt','acpa_zero_price')
->first();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['adm_info'] = $adm_info; //结款人数据
$data_info['account_info'] = $account_info; //会计科目数据
$data_info['total_data'] = $total_data; //搜索统计数据
// 获取当前列表下的按钮
// $list_button = getListButton($request['api_token'], $request['pri_id']);
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info]);
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyProcurementDetailController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
use App\Http\Models\Api\Export;
class ProcurementDetailController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 采购明细
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementDetailController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
if(!empty($search_data['proc_create_time']) || !empty($search_data['proc_number']) || !empty($search_data['prgo_goo_id']) | !empty($search_data['proc_chun_id']) || !empty($search_data['chun_adm_id']) || !empty($search_data['proc_ware_id']) || !empty($search_data['shop_type']) || !empty($search_data['proc_shop_id'])){
$list_data = DB::table('procurement_goods as g')
->leftjoin('procurement as p','g.prgo_proc_id','=','p.proc_id')
->leftjoin('channel_unit as u','p.proc_chun_id','=','u.chun_id')
->leftjoin('shop as s','s.shop_id','=','p.proc_shop_id')
->where('proc_cid',$user_info->adm_cid)
->where('proc_superior_shop_id',$shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['proc_create_time'])) {
$query->where('proc_create_time','like','%'. $search_data['proc_create_time'].'%');
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['proc_number'])) {
$query->where('proc_number','like', '%' . $search_data['proc_number'].'%');
}
}) //单号
->where(function($query) use($search_data) {
if (!empty($search_data['prgo_goo_id'])) {
$query->where('prgo_goo_id', $search_data['prgo_goo_id']);
}
}) //商品名称
->where(function($query) use($search_data) {
if (!empty($search_data['proc_chun_id'])) {
$query->where('proc_chun_id', $search_data['proc_chun_id']);
}
}) //客户单位
->where(function($query) use($search_data) {
if (!empty($search_data['chun_adm_id'])) {
$query->where('chun_adm_id', $search_data['chun_adm_id']);
}
}) //业务员
->where(function($query) use($search_data) {
if (!empty($search_data['proc_ware_id'])) {
$query->where('proc_ware_id', $search_data['proc_ware_id']);
}
}) //仓库名称
->where(function($query) use($search_data) {
if (!empty($search_data['shop_type'])) {
$query->where('shop_type', $search_data['shop_type']);
}
}) //门店类型
->where(function($query) use($search_data) {
if (!empty($search_data['proc_shop_id'])) {
$query->where('proc_shop_id', $search_data['proc_shop_id']);
}
}) //门店名称
->select('prgo_id', 'proc_create_time', 'proc_number', 'proc_shop_id', 'proc_ware_id',
'chun_unit_name', 'proc_chun_id', 'chun_adm_id', 'prgo_goo_id', 'prgo_purchase_number',
'prgo_purchase_price', 'proc_actual_price', 'shop_store_name', 'shop_type','prgo_actual_number')
->orderBy('prgo_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$sum_type = 2; //显示
$sum_data = DB::table('procurement_goods as g')
->leftjoin('procurement as p','g.prgo_proc_id','=','p.proc_id')
->leftjoin('channel_unit as u','p.proc_chun_id','=','u.chun_id')
->leftjoin('shop as s','s.shop_id','=','p.proc_shop_id')
->where('proc_cid',$user_info->adm_cid)
->where('proc_superior_shop_id',$shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['proc_create_time'])) {
$query->where('proc_create_time','like','%'. $search_data['proc_create_time'].'%');
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['proc_number'])) {
$query->where('proc_number','like', '%' . $search_data['proc_number'].'%');
}
}) //单号
->where(function($query) use($search_data) {
if (!empty($search_data['prgo_goo_id'])) {
$query->where('prgo_goo_id', $search_data['prgo_goo_id']);
}
}) //商品名称
->where(function($query) use($search_data) {
if (!empty($search_data['proc_chun_id'])) {
$query->where('proc_chun_id', $search_data['proc_chun_id']);
}
}) //客户单位
->where(function($query) use($search_data) {
if (!empty($search_data['chun_adm_id'])) {
$query->where('chun_adm_id', $search_data['chun_adm_id']);
}
}) //业务员
->where(function($query) use($search_data) {
if (!empty($search_data['proc_ware_id'])) {
$query->where('proc_ware_id', $search_data['proc_ware_id']);
}
}) //仓库名称
->where(function($query) use($search_data) {
if (!empty($search_data['shop_type'])) {
$query->where('shop_type', $search_data['shop_type']);
}
}) //门店类型
->where(function($query) use($search_data) {
if (!empty($search_data['proc_shop_id'])) {
$query->where('proc_shop_id', $search_data['proc_shop_id']);
}
}) //门店名称
->first(array(
\DB::raw('SUM(prgo_purchase_number) as sum_number'),
\DB::raw('SUM(proc_actual_price) as sum_price')
));
if ($list_items) {
$sum_number = 0; //商品采购总数量
$sum_price = 0; //总采购金额
foreach ($list_items as $key => $value) {
$ware_id[] = $value->proc_ware_id; //仓库id
$adm_id[] = $value->chun_adm_id; //业务员id
$goo_id[] = $value->prgo_goo_id; //商品id
$list_items[$key]->total_money = $value->prgo_actual_number * $value->prgo_purchase_price ;//商品合计金额
}
// 仓库信息
$ware_info = DB::table('warehouse')
->whereIn('ware_id',$ware_id)
->get(['ware_id','ware_name']);
// 业务员信息
$adm_info = DB::table('admin')
->whereIn('adm_id',$adm_id)
->get(['adm_id','adm_name']);
// 商品信息
$goo_info = DB::table('goods')
->whereIn('goo_id',$goo_id)
->get(['goo_id','goo_name','goo_goods_code','goo_goods_encode']);
}else{
$ware_info = [];
$adm_info = [];
$goo_info = [];
}
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['ware_info'] = $ware_info; //单位类型数据
$data_info['adm_info'] = $adm_info; //业务员/录单人数据
$data_info['goo_info'] = $goo_info; //商品数据
$data_info['sum_number'] = empty($sum_data->sum_number)?0:$sum_data->sum_number; //商品采购总数量
$data_info['sum_price'] = empty($sum_data->sum_price)?0:$sum_data->sum_price; //总采购金额
}else{
$list_items = [];
$sum_type = 1; //隐藏
}
$data_info['sum_type'] = $sum_type; //1.隐藏 2.显示
$data_info['data'] = $list_items; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}
// 导出
public function export(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$data = DB::table('procurement_goods as g')
->leftjoin('procurement as p','g.prgo_proc_id','=','p.proc_id')
->leftjoin('channel_unit as u','p.proc_chun_id','=','u.chun_id')
->leftjoin('shop as s','s.shop_id','=','p.proc_shop_id')
->where('proc_cid',$user_info->adm_cid)
->where('proc_superior_shop_id',$shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['proc_create_time'])) {
$query->where('proc_create_time','like','%'. $search_data['proc_create_time'].'%');
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['proc_number'])) {
$query->where('proc_number','like', '%' . $search_data['proc_number'].'%');
}
}) //单号
->where(function($query) use($search_data) {
if (!empty($search_data['prgo_goo_id'])) {
$query->where('prgo_goo_id', $search_data['prgo_goo_id']);
}
}) //商品名称
->where(function($query) use($search_data) {
if (!empty($search_data['proc_chun_id'])) {
$query->where('proc_chun_id', $search_data['proc_chun_id']);
}
}) //客户单位
->where(function($query) use($search_data) {
if (!empty($search_data['chun_adm_id'])) {
$query->where('chun_adm_id', $search_data['chun_adm_id']);
}
}) //业务员
->where(function($query) use($search_data) {
if (!empty($search_data['proc_ware_id'])) {
$query->where('proc_ware_id', $search_data['proc_ware_id']);
}
}) //仓库名称
->where(function($query) use($search_data) {
if (!empty($search_data['shop_type'])) {
$query->where('shop_type', $search_data['shop_type']);
}
}) //门店类型
->where(function($query) use($search_data) {
if (!empty($search_data['proc_shop_id'])) {
$query->where('proc_shop_id', $search_data['proc_shop_id']);
}
}) //门店名称
->select('proc_create_time', 'proc_number', 'shop_type', 'shop_store_name', 'proc_ware_id',
'chun_unit_name', 'chun_adm_id', 'prgo_goo_id', 'prgo_id','prgo_purchase_number',
'prgo_purchase_price', 'proc_actual_price')
->orderBy('prgo_id', 'desc')
->get();
if (!empty($data)) {
// 将对象转化为数组
$data = json_decode(json_encode($data),true);
foreach ($data as $key => $value) {
//仓库id
$ware_id[] = $value['proc_ware_id'];
//业务员id
$adm_id[] = $value['chun_adm_id'];
//商品id
$goo_id[] = $value['prgo_goo_id'];
}
$ware_id = array_unique($ware_id);
$adm_id = array_unique($adm_id);
$goo_id = array_unique($goo_id);
// 仓库信息
$ware_info = DB::table('warehouse')->whereIn('ware_id',$ware_id)->pluck('ware_name', 'ware_id');
// 业务员信息
$adm_info = DB::table('admin')->whereIn('adm_id',$adm_id)->pluck('adm_name', 'adm_id');
// 商品信息
$goo_info = collect(DB::table('goods')->whereIn('goo_id',$goo_id)->get(['goo_name','goo_goods_code','goo_id']))->keyBy('goo_id')->toArray();
foreach ($data as $key => $value) {
//仓库名称
$data[$key]['proc_ware_id'] = $ware_info[$value['proc_ware_id']];
// 业务员姓名
$data[$key]['chun_adm_id'] = $adm_info[$value['chun_adm_id']];
// 商品名称/编号
$data[$key]['prgo_goo_id'] = $goo_info[$value['prgo_goo_id']]->goo_name;
$data[$key]['prgo_id'] = $goo_info[$value['prgo_goo_id']]->goo_goods_code;
// 门店类型
if($value['shop_type'] == 1){$data[$key]['shop_type'] = '总店';}
if($value['shop_type'] == 2){$data[$key]['shop_type'] = '直营店';}
if($value['shop_type'] == 3){$data[$key]['shop_type'] = '加盟店';}
// 单价除100
// 合计金额除100
$data[$key]['prgo_purchase_price'] = $data[$key]['prgo_purchase_price'] / 100;
$data[$key]['proc_actual_price'] = $data[$key]['proc_actual_price'] / 100;
}
}
$pathName = storage_path()."/app/public/excel";//获取上传excel路径
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName,0775,true);
chmod($pathName,0775);
}
$streamFileRand = time() . rand(10000,99999).'.xls';//
// 产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
$streamFilename = $pathName . '/' .$streamFileRand;
$where['action_name'] = '采购明细'; //
$where['field_name'] = ['创建时间','单号','门店类型','门店名称','仓库名称','单位名称','业务员','商品名称',
'商品编号','采购数量','采购单价','合计'];
// 调用导出的公共方法
export::publicExport(
$streamFilename, //路径
$where, //sheet名及其每一行的标题
$data //导出数据
);
// 判断文件是否存在 存在则成功 不存在则失败
if(file_exists($pathName))
{
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>'storage/excel/'.$streamFileRand]);
}else{
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'导出失败']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifySellDetailController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
use App\Http\Models\Api\Export;
class SellDetailController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 商品销量
public function goodsSales(Request $request)
{
// 验证数据
$verify_data = new VerifySellDetailController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
if (!empty($search_data['start_time']) || !empty($search_data['end_time']) || !empty($search_data['sede_order_number']) || !empty($search_data['goo_bra_id']) || !empty($search_data['goo_cate_id']) || !empty($search_data['sede_goo_id']) || !empty($search_data['shop_id']) || !empty($search_data['chun_id']) || !empty($search_data['sede_orla_id']) || !empty($search_data['ware_freight_space']) || !empty($search_data['goo_goods_encode']) || !empty($search_data['chun_chty_id']) || !empty($search_data['chin_zoning'])) {
$list_data = DB::table('sell_detail as sede')
->leftjoin('goods as goo','goo.goo_id','=','sede.sede_goo_id')
->leftjoin('channel_unit as chun','chun.chun_id','=','sede.sede_client_id')
->leftjoin('warehouse as w','w.ware_id','=','sede.sede_ware_id')
->leftjoin('channel_info as chin','chin.chin_chun_id','=','sede.sede_client_id')
->where('sede_cid',$user_info->adm_cid)
->where('sede_superior_shop_id',$shop_id)
->where('sede_client_type',2)
->where('sede_goo_state','!=',2) //商品状态1正常2删除3回收的商品4换货商品
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])){
$query->whereBetween('sede_create_time',[$search_data['start_time'],$search_data['end_time'].' 23:59:59']);
}else{
// 如果选择开始时间
if (!empty($search_data['start_time'])){
$query->where('sede_create_time','>=',$search_data['start_time']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('sede_create_time','<=',$search_data['end_time'].' 23:59:59');
}
}
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['sede_order_number'])) {
$query->where('sede_order_number','like','%'. $search_data['sede_order_number'].'%');
}
}) //单号编号
->where(function($query) use($search_data) {
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo_bra_id', $search_data['goo_bra_id']);
}
}) //品牌名称
->where(function($query) use($search_data) {
if (!empty($search_data['goo_cate_id'])) {
$query->where('goo_cate_id', $search_data['goo_cate_id']);
}
}) //品类名称
->where(function($query) use($search_data) {
if (!empty($search_data['sede_goo_id'])) {
$query->where('sede_goo_id', $search_data['sede_goo_id']);
}
}) //商品名称
->where(function($query) use($search_data) {
if (!empty($search_data['shop_id'])) {
$query->where('sede_service_shop_id', $search_data['shop_id']);
}
}) //门店名称
->where(function($query) use($search_data) {
if (!empty($search_data['chun_id'])) {
$query->where('chun_id', $search_data['chun_id']);
}
}) //客户单位
->where(function($query) use($search_data) {
if (!empty($search_data['sede_orla_id'])) {
$query->where('sede_orla_id', $search_data['sede_orla_id']);
}
}) //订单标签
->where(function($query) use($search_data) {
if (!empty($search_data['ware_freight_space'])) {
$query->where('ware_freight_space','like','%'. $search_data['ware_freight_space'].'%');
}
}) //仓位名称
->where(function($query) use($search_data) {
if (!empty($search_data['goo_goods_encode'])) {
$query->where('goo_goods_encode','like','%'. $search_data['goo_goods_encode'].'%');
}
}) //产品编码
->where(function($query) use($search_data) {
if (!empty($search_data['chun_chty_id'])) {
$query->where('chun_chty_id','like',$search_data['chun_chty_id']);
}
}) //单位类型
->where(function($query) use($search_data) {
if (!empty($search_data['chin_zoning'])) {
$query->where('chin_zoning','like', '%'.$search_data['chin_zoning'].'%');
}
}) //业务划区
->select('sede_id', 'sede_create_time', 'sede_order_number', 'sede_create_id',
'goo_bra_name', 'goo_cate_name', 'goo_name', 'chun_chty_id', 'chun_unit_name',
'sede_service_shop_id', 'chun_adm_id', 'sede_goo_quantity', 'sede_goo_price',
'sede_amount_price', 'sede_plus_minus', 'chun_search_letter', 'sede_orla_id',
'ware_freight_space', 'goo_goods_encode', 'sede_remarks', 'sede_order_type')
->orderBy('sede_id','desc')
->paginate($this->show_count);
$list_items = $list_data->items();
$sum_type = 2;
$sum_data = DB::table('sell_detail as sede')
->leftjoin('goods as goo','goo.goo_id','=','sede.sede_goo_id')
->leftjoin('channel_unit as chun','chun.chun_id','=','sede.sede_client_id')
->leftjoin('warehouse as w','w.ware_id','=','sede.sede_ware_id')
->leftjoin('channel_info as chin','chin.chin_chun_id','=','sede.sede_client_id')
->where('sede_cid',$user_info->adm_cid)
->where('sede_superior_shop_id',$shop_id)
->where('sede_client_type',2)
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])){
$query->whereBetween('sede_create_time',[$search_data['start_time'],$search_data['end_time'].' 23:59:59']);
}else{
// 如果选择开始时间
if (!empty($search_data['start_time'])){
$query->where('sede_create_time','>=',$search_data['start_time']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('sede_create_time','<=',$search_data['end_time'].' 23:59:59');
}
}
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['sede_order_number'])) {
$query->where('sede_order_number','like','%'. $search_data['sede_order_number'].'%');
}
}) //单号编号
->where(function($query) use($search_data) {
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo_bra_id', $search_data['goo_bra_id']);
}
}) //品牌名称
->where(function($query) use($search_data) {
if (!empty($search_data['goo_cate_id'])) {
$query->where('goo_cate_id', $search_data['goo_cate_id']);
}
}) //品类名称
->where(function($query) use($search_data) {
if (!empty($search_data['sede_goo_id'])) {
$query->where('sede_goo_id', $search_data['sede_goo_id']);
}
}) //商品名称
->where(function($query) use($search_data) {
if (!empty($search_data['shop_id'])) {
$query->where('sede_service_shop_id', $search_data['shop_id']);
}
}) //门店名称
->where(function($query) use($search_data) {
if (!empty($search_data['chun_id'])) {
$query->where('chun_id', $search_data['chun_id']);
}
}) //客户单位
->where(function($query) use($search_data) {
if (!empty($search_data['sede_orla_id'])) {
$query->where('sede_orla_id', $search_data['sede_orla_id']);
}
}) //订单标签
->where(function($query) use($search_data) {
if (!empty($search_data['ware_freight_space'])) {
$query->where('ware_freight_space','like','%'. $search_data['ware_freight_space'].'%');
}
}) //仓位名称
->where(function($query) use($search_data) {
if (!empty($search_data['goo_goods_encode'])) {
$query->where('goo_goods_encode','like','%'. $search_data['goo_goods_encode'].'%');
}
}) //产品编码
->where(function($query) use($search_data) {
if (!empty($search_data['chun_chty_id'])) {
$query->where('chun_chty_id','like',$search_data['chun_chty_id']);
}
}) //单位类型
->where(function($query) use($search_data) {
if (!empty($search_data['chin_zoning'])) {
$query->where('chin_zoning','like', '%'.$search_data['chin_zoning'].'%');
}
}) //业务划区
->first(array(
\DB::raw('SUM(sede_goo_quantity) as sum_count'),
\DB::raw('SUM(sede_amount_price) as sum_price')
));
if ($list_items) {
foreach ($list_items as $key => $value) {
$shop_store_id[] = $value->sede_service_shop_id; //门店id
$chty_id[] = $value->chun_chty_id; //单位类型id
$adm_id[] = $value->chun_adm_id; //业务员id
$adm_id[] = $value->sede_create_id; //录单人id
$orla_id[] = $value->sede_orla_id; //订单标签id
}
// 查找单位类型
$type_info = DB::table('channel_type')
->whereIn('chty_id',$chty_id)
->select('chty_id','chty_name')
->get();
// 查找业务员
$adm_info = DB::table('admin')
->whereIn('adm_id',$adm_id)
->select('adm_id','adm_name')
->get();
// 查找门店
$shop_info = DB::table('shop')
->whereIn('shop_id',$shop_store_id)
->select('shop_id','shop_store_name')
->get();
// 查找订单标签
$orla_info = DB::table('order_label')
->whereIn('orla_id',$orla_id)
->select('orla_id','orla_name')
->get();
} else {
$type_info = [];
$adm_info = [];
$shop_info = [];
$orla_info = [];
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['type_info'] = $type_info; //单位类型数据
$data_info['adm_info'] = $adm_info; //业务员/录单人数据
$data_info['shop_info'] = $shop_info; //门店数据
$data_info['orla_info'] = $orla_info; //订单标签数据
$data_info['sum_count'] = empty($sum_data->sum_count)?0:$sum_data->sum_count; //返回总数量
$data_info['sum_price'] = empty($sum_data->sum_price)?0:$sum_data->sum_price; //返回总金额
} else {
$list_items = [];
$sum_type = 1; //隐藏
}
$data_info['sum_type'] = $sum_type; //返回总数量
$data_info['data'] = $list_items; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}
// 商品销量
public function goodsSales2(Request $request)
{
// 验证数据
$verify_data = new VerifySellDetailController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
if(!empty($search_data['start_time']) || !empty($search_data['end_time']) || !empty($search_data['ord_order_number']) || !empty($search_data['ord_create_id']) || !empty($search_data['goo_bra_id']) || !empty($search_data['goo_cate_id']) || !empty($search_data['orgo_goo_id']) || !empty($search_data['shop_id']) || !empty($search_data['chun_id']))
{
$list_data = DB::table('order_goods as g')
->leftjoin('order as o','g.orgo_ord_id','=','o.ord_id')
->leftjoin('goods as goo','g.orgo_goo_id','=','goo.goo_id')
->leftjoin('channel_unit as u','o.ord_client_id','=','u.chun_id')
->where('ord_cid',$user_info->adm_cid)
->where('ord_superior_shop_id',$shop_id)
->where('ord_type',2)
->where('orgo_state', '!=', 2) //商品状态1.正常 2.删除3回收的商品
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])){
$query->whereBetween('ord_create_time',[$search_data['start_time'],$search_data['end_time']]);
}else{
// 如果选择开始时间
if (!empty($search_data['start_time'])){
$query->where('ord_create_time','>=',$search_data['start_time']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('ord_create_time','<=',$search_data['end_time']);
}
}
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['ord_order_number'])) {
$query->where('ord_order_number','like','%'. $search_data['ord_order_number'].'%');
}
}) //单号编号
->where(function($query) use($search_data) {
if (!empty($search_data['ord_create_id'])) {
$query->where('ord_create_id', $search_data['ord_create_id']);
}
}) //录单人员
->where(function($query) use($search_data) {
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo_bra_id', $search_data['goo_bra_id']);
}
}) //品牌名称
->where(function($query) use($search_data) {
if (!empty($search_data['goo_cate_id'])) {
$query->where('goo_cate_id', $search_data['goo_cate_id']);
}
}) //品类名称
->where(function($query) use($search_data) {
if (!empty($search_data['orgo_goo_id'])) {
$query->where('orgo_goo_id', $search_data['orgo_goo_id']);
}
}) //商品名称
->where(function($query) use($search_data) {
if (!empty($search_data['shop_id'])) {
$query->where('ord_shop_id', $search_data['shop_id']);
}
}) //门店名称
->where(function($query) use($search_data) {
if (!empty($search_data['chun_id'])) {
$query->where('chun_id', $search_data['chun_id']);
}
}) //客户单位
->select('orgo_id', 'orgo_goo_name', 'orgo_goo_quantity', 'orgo_goo_price', 'ord_create_time',
'ord_order_number', 'ord_create_id', 'goo_bra_name', 'goo_bra_id', 'goo_cate_name',
'goo_cate_id','ord_actual_price','orgo_goo_id','chun_unit_name','chun_chty_id',
'chun_adm_id','ord_shop_id','chun_id','ord_delete','orgo_goo_exchange','ord_service_type')
->orderBy('orgo_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
$sum_type = 2;
$sum_data = DB::table('order_goods as g')
->leftjoin('order as o','g.orgo_ord_id','=','o.ord_id')
->leftjoin('goods as goo','g.orgo_goo_id','=','goo.goo_id')
->leftjoin('channel_unit as u','o.ord_client_id','=','u.chun_id')
->where('ord_cid',$user_info->adm_cid)
->where('ord_superior_shop_id',$shop_id)
->where('ord_type',2)
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])){
$query->whereBetween('ord_create_time',[$search_data['start_time'],$search_data['end_time']]);
}else{
// 如果选择开始时间
if (!empty($search_data['start_time'])){
$query->where('ord_create_time','>=',$search_data['start_time']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('ord_create_time','<=',$search_data['end_time']);
}
}
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['ord_order_number'])) {
$query->where('ord_order_number','like','%'. $search_data['ord_order_number'].'%');
}
}) //单号编号
->where(function($query) use($search_data) {
if (!empty($search_data['ord_create_id'])) {
$query->where('ord_create_id', $search_data['ord_create_id']);
}
}) //录单人员
->where(function($query) use($search_data) {
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo_bra_id', $search_data['goo_bra_id']);
}
}) //品牌名称
->where(function($query) use($search_data) {
if (!empty($search_data['goo_cate_id'])) {
$query->where('goo_cate_id', $search_data['goo_cate_id']);
}
}) //品类名称
->where(function($query) use($search_data) {
if (!empty($search_data['orgo_goo_id'])) {
$query->where('orgo_goo_id', $search_data['orgo_goo_id']);
}
}) //商品名称
->where(function($query) use($search_data) {
if (!empty($search_data['shop_id'])) {
$query->where('ord_shop_id', $search_data['shop_id']);
}
}) //门店名称
->where(function($query) use($search_data) {
if (!empty($search_data['chun_id'])) {
$query->where('chun_id', $search_data['chun_id']);
}
}) //客户单位
->first(array(
\DB::raw('SUM(orgo_goo_quantity) as sum_count'),
\DB::raw('SUM(ord_actual_price) as sum_price')
));
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['data'] = $list_items; //返回数据
}else{
$list_data = [];
$data_info = [];
$list_items = '';
$sum_type = 1; //隐藏
}
if ($list_items) {
foreach ($list_items as $key => $value) {
$shop_store_id[] = $value->ord_shop_id; //门店id
$chty_id[] = $value->chun_chty_id; //单位类型id
$adm_id[] = $value->chun_adm_id; //业务员id
$adm_id[] = $value->ord_create_id; //录单人id
}
// 查找单位类型
$type_info = DB::table('channel_type')
->whereIn('chty_id',$chty_id)
->get(['chty_id','chty_name']);
// 查找业务员
$adm_info = DB::table('admin')
->whereIn('adm_id',$adm_id)
->get(['adm_id','adm_name']);
// 查找门店
$shop_info = DB::table('shop')
->whereIn('shop_id',$shop_store_id)
->get(['shop_id','shop_store_name']);
}else{
$type_info = [];
$adm_info = [];
$shop_info = [];
}
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['type_info'] = $type_info; //单位类型数据
$data_info['adm_info'] = $adm_info; //业务员/录单人数据
$data_info['shop_info'] = $shop_info; //门店数据
$data_info['sum_type'] = $sum_type; //返回总数量
$data_info['sum_count'] = empty($sum_data->sum_count)?0:$sum_data->sum_count; //返回总数量
$data_info['sum_price'] = empty($sum_data->sum_price)?0:$sum_data->sum_price; //返回总金额
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 商品销量导出
public function export(Request $request)
{
$search_data = $request->all();
if (!empty($search_data['start_time']) || !empty($search_data['end_time']) || !empty($search_data['sede_order_number']) || !empty($search_data['goo_bra_id']) || !empty($search_data['goo_cate_id']) || !empty($search_data['sede_goo_id']) || !empty($search_data['shop_id']) || !empty($search_data['chun_id']) || !empty($search_data['sede_orla_id']) || !empty($search_data['ware_freight_space']) || !empty($search_data['goo_goods_encode']) || !empty($search_data['chun_chty_id']) || !empty($search_data['chin_zoning'])) {
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$list_data = DB::table('sell_detail as sede')
->leftjoin('goods as goo','goo.goo_id','=','sede.sede_goo_id')
->leftjoin('channel_unit as chun','chun.chun_id','=','sede.sede_client_id')
->leftjoin('warehouse as w','w.ware_id','=','sede.sede_ware_id')
->leftjoin('channel_info as chin','chin.chin_chun_id','=','sede.sede_client_id')
->where('sede_cid',$user_info->adm_cid)
->where('sede_superior_shop_id',$shop_id)
->where('sede_client_type',2)
->where('sede_goo_state','!=',2) //商品状态1正常2删除3回收的商品4换货商品
->where(function($query) use($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])){
$query->whereBetween('sede_create_time',[$search_data['start_time'],$search_data['end_time'].' 23:59:59']);
}else{
// 如果选择开始时间
if (!empty($search_data['start_time'])){
$query->where('sede_create_time','>=',$search_data['start_time']);
}else{
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('sede_create_time','<=',$search_data['end_time'].' 23:59:59');
}
}
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['sede_order_number'])) {
$query->where('sede_order_number','like','%'. $search_data['sede_order_number'].'%');
}
}) //单号编号
->where(function($query) use($search_data) {
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo_bra_id', $search_data['goo_bra_id']);
}
}) //品牌名称
->where(function($query) use($search_data) {
if (!empty($search_data['goo_cate_id'])) {
$query->where('goo_cate_id', $search_data['goo_cate_id']);
}
}) //品类名称
->where(function($query) use($search_data) {
if (!empty($search_data['sede_goo_id'])) {
$query->where('sede_goo_id', $search_data['sede_goo_id']);
}
}) //商品名称
->where(function($query) use($search_data) {
if (!empty($search_data['shop_id'])) {
$query->where('sede_service_shop_id', $search_data['shop_id']);
}
}) //门店名称
->where(function($query) use($search_data) {
if (!empty($search_data['chun_id'])) {
$query->where('chun_id', $search_data['chun_id']);
}
}) //客户单位
->where(function($query) use($search_data) {
if (!empty($search_data['sede_orla_id'])) {
$query->where('sede_orla_id', $search_data['sede_orla_id']);
}
}) //订单标签
->where(function($query) use($search_data) {
if (!empty($search_data['ware_freight_space'])) {
$query->where('ware_freight_space','like','%'. $search_data['ware_freight_space'].'%');
}
}) //仓位名称
->where(function($query) use($search_data) {
if (!empty($search_data['goo_goods_encode'])) {
$query->where('goo_goods_encode','like','%'. $search_data['goo_goods_encode'].'%');
}
}) //产品编码
->where(function($query) use($search_data) {
if (!empty($search_data['chun_chty_id'])) {
$query->where('chun_chty_id','like',$search_data['chun_chty_id']);
}
}) //单位类型
->where(function($query) use($search_data) {
if (!empty($search_data['chin_zoning'])) {
$query->where('chin_zoning','like', '%'.$search_data['chin_zoning'].'%');
}
}) //业务划区
->select('sede_create_time', 'sede_order_number', 'sede_create_id', 'goo_bra_name', 'goo_cate_name', 'goo_name', 'goo_goods_encode', 'sede_goo_quantity', 'chun_chty_id', 'chun_unit_name', 'sede_service_shop_id', 'chun_adm_id', 'sede_goo_price', 'sede_amount_price')
->orderBy('sede_id','desc')
->get();
$data = json_decode(json_encode($list_data),true);
// dump($data);exit;
if (!empty($data)) {
foreach ($data as $key => $value) {
$shop_store_id[] = $value['sede_service_shop_id']; //门店id
$chty_id[] = $value['chun_chty_id']; //单位类型id
$adm_id[] = $value['chun_adm_id']; //业务员id
$adm_id[] = $value['sede_create_id']; //录单人id
// $orla_id[] = $value['sede_orla_id']; //订单标签id
}
$shop_store_id = array_unique($shop_store_id);
$chty_id = array_unique($chty_id);
$adm_id = array_unique($adm_id);
// $orla_id = array_unique($orla_id);
// 查找单位类型
$type_info = DB::table('channel_type')->whereIn('chty_id',$chty_id)->pluck('chty_name','chty_id');
// dump($type_info);exit;
// 查找门店
$shop_info = DB::table('shop')->whereIn('shop_id',$shop_store_id)->pluck('shop_store_name','shop_id');
// 查找业务员/录单人
$adm_info = DB::table('admin')->whereIn('adm_id',$adm_id)->pluck('adm_name','adm_id');
// 查找订单标签
// $orla_info = DB::table('order_label')->whereIn('orla_id',$orla_id)->pluck('orla_id','orla_name');
foreach ($data as $key => $value) {
// 单位类型名称
if (isset($type_info[$value['chun_chty_id']])) {
$data[$key]['chun_chty_id'] = $type_info[$value['chun_chty_id']];
} else {
$data[$key]['chun_chty_id'] = '';
}
// 门店名称
if (isset($shop_info[$value['sede_service_shop_id']])) {
$data[$key]['sede_service_shop_id'] = $shop_info[$value['sede_service_shop_id']];
} else {
$data[$key]['sede_service_shop_id'] = '';
}
// 业务员姓名
if (isset($adm_info[$value['chun_adm_id']])) {
$data[$key]['chun_adm_id'] = $adm_info[$value['chun_adm_id']];
} else {
$data[$key]['chun_adm_id'] = '';
}
// 录单人姓名
if ($adm_info[$value['sede_create_id']]) {
$data[$key]['sede_create_id'] = $adm_info[$value['sede_create_id']];
} else {
$data[$key]['sede_create_id'] = '';
}
// 单价除100
$data[$key]['sede_goo_price'] = $data[$key]['sede_goo_price'] / 100;
// 合计金额除100
$data[$key]['sede_amount_price'] = $data[$key]['sede_amount_price'] / 100;
}
} else {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'暂无导出数据']);
}
$pathName = storage_path()."/app/public/excel";//获取上传excel路径
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName,0775,true);
chmod($pathName,0775);
}
$streamFileRand = time() . rand(10000,99999).'.xls';//
// 产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
$streamFilename = $pathName . '/' .$streamFileRand;
$where['action_name'] = '销售';
$where['field_name'] = ['创建时间', '单号', '录单人员', '品牌名称', '品类名称', '商品名称', '检索编号', '销售数量', '单位类型', '单位名称', '门店名称', '业务人员', '单价', '合计'];
// 调用导出的公共方法
export::publicExport(
$streamFilename, //路径
$where, //sheet名及其每一行的标题
$data //导出数据
);
// 判断文件是否存在 存在则成功 不存在则失败
if(file_exists($pathName)) {
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>'storage/excel/'.$streamFileRand]);
}else{
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'导出失败']);
}
}else{
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'请输入搜索条件']);
}
}
// 客户销量
public function clientSales(Request $request)
{
// 验证数据
$verify_data = new VerifySellDetailController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('channel_sales as s')
->leftjoin('channel_unit as u','s.chsa_client_id','=','u.chun_id')
->where('chsa_cid',$user_info->adm_cid)
->where('chsa_superior_shop_id',$shop_id)
->where('chsa_type',2)
->where(function($query) use($search_data) {
if (!empty($search_data['chsa_create_time'])) {
$query->where('chsa_create_time','like', $search_data['chsa_create_time'].'%');
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['chsa_chty_id'])) {
$query->where('chsa_chty_id', $search_data['chsa_chty_id']);
}
}) //单位类型
->where(function($query) use($search_data) {
if (!empty($search_data['chsa_client_id'])) {
$query->where('chsa_client_id', $search_data['chsa_client_id']);
}
}) //客户单位
->where(function($query) use($search_data) {
if (!empty($search_data['chun_adm_id'])) {
$query->where('chun_adm_id', $search_data['chun_adm_id']);
}
}) //业务员
->select('chsa_id', 'chsa_create_time', 'chsa_type', 'chsa_chty_id', 'chun_unit_name',
'chun_adm_id', 'chsa_ord_number', 'chsa_sales_number', 'chsa_total_price')
->orderBy('chsa_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
foreach ($list_items as $key => $value) {
$chty_id[] = $value->chsa_chty_id; //单位类型id
$adm_id[] = $value->chun_adm_id; //业务员id
}
// 查找单位类型
$type_info = DB::table('channel_type')
->whereIn('chty_id',$chty_id)
->get(['chty_id','chty_name']);
// 查找业务员
$adm_info = DB::table('admin')
->whereIn('adm_id',$adm_id)
->get(['adm_id','adm_name']);
}else{
$type_info = [];
$adm_info = [];
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['type_info'] = $type_info; //单位类型数据
$data_info['adm_info'] = $adm_info; //业务员/录单人数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 门店销量
public function shopSales(Request $request)
{
// 验证数据
$verify_data = new VerifySellDetailController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('shop_sales as acset')
->where('shoa_cid',$user_info->adm_cid)
->where('shoa_superior_shop_id',$shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['shoa_create_time'])) {
$query->where('shoa_create_time','like', '%' . $search_data['shoa_create_time'].'%');
}
}) //创建时间
->where(function($query) use($search_data) {
if (!empty($search_data['shoa_type'])) {
$query->where('shoa_type', $search_data['shoa_type']);
}
}) //门店类型
->where(function($query) use($search_data) {
if (!empty($search_data['shoa_shop_id'])) {
$query->where('shoa_shop_id', $search_data['shoa_shop_id']);
}
}) //门店名称
->select('shoa_id', 'shoa_create_time', 'shoa_type', 'shoa_shop_id', 'shoa_ord_number',
'shoa_sales_number', 'shoa_total_price')
->orderBy('shoa_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
foreach ($list_items as $key => $value) {
$shoa_shop_id[] = $value->shoa_shop_id; //单位类型id
}
// 查找单位类型
$shop_info = DB::table('shop')
->whereIn('shop_id',$shoa_shop_id)
->get(['shop_id','shop_name']);
}else{
$shop_info = [];
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['shop_info'] = $shop_info; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 下拉搜索商品
public function searchGoods(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$data_info = DB::table('goods')
->where('goo_cid',$user_info->adm_cid)
->where('goo_superior_shop_id',$shop_id)
->where('goo_delete',1)
->where('goo_state',1)
->where(function($query) use($search_data) {
if (!empty($search_data['search_data'])) {
$query->where('goo_name','like', '%'. $search_data['search_data'].'%');
}
}) //商品名称
->get(['goo_id', 'goo_name']);
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info]);
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Models\Api\Common;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifySellProjectController;
class SellProjectController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 销售利润
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifySellProjectController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
if (!empty($search_data['sede_goo_id']) || !empty($search_data['goo_bra_id']) || !empty($search_data['start_time']) || !empty($search_data['end_time']) || !empty($search_data['sede_shop_id']) || !empty($search_data['chun_id'])) {
$list_data = DB::table('sell_detail as sede')
->leftjoin('goods as goo', 'sede.sede_goo_id', '=', 'goo.goo_id')
->leftjoin('channel_unit as chun', 'chun.chun_id', '=', 'sede.sede_client_id')
->where('sede_cid', $user_info->adm_cid)
->where('sede_superior_shop_id', $shop_id)
->where('sede_plus_minus', 1)
->where(function ($query) use ($search_data) {
if (!empty($search_data['sede_goo_id'])) {
$query->where('sede_goo_id', $search_data['sede_goo_id']);
}
}) //商品名称
->where(function ($query) use ($search_data) {
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo_bra_id', $search_data['goo_bra_id']);
}
}) //品牌名称
->where(function ($query) use ($search_data) {
if (!empty($search_data['sede_shop_id'])) {
$query->where('sede_shop_id', $search_data['sede_shop_id']);
}
}) //品牌名称
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])) {
$query->whereBetween('sede_create_time', [$search_data['start_time'], $search_data['end_time'] . ' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['start_time'])) {
$query->where('sede_create_time', '>=', $search_data['start_time']);
} else {
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('sede_create_time', '<=', $search_data['end_time'] . ' 23:59:59');
}
}
}
}) //创建时间
->where(function ($query) use ($search_data) {
if (!empty($search_data['chun_id'])) {
$query->where('chun_id', $search_data['chun_id']);
}
}) //客户单位
->select(DB::raw('sede_id, goo_name, goo_bra_id, goo_bra_name, goo_goods_encode, sede_order_type, sum(sede_cost_amount_price) as sede_cost_amount_price, sum(sede_amount_price) as sede_amount_price, sum(sede_goo_quantity) as sede_goo_quantity, sede_plus_minus,sede_create_time, sede_order_type, sede_shop_id, sede_superior_shop_id, sede_goo_id, chun_unit_name'))
->groupBy('sede_goo_id')
->orderBy('sede_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if (!empty($list_items)) {
$sede_goo_id = array_column($list_items, 'sede_goo_id');
//退货总金额
$goods = DB::table('sell_detail as sede')
->leftjoin('goods as goo', 'sede.sede_goo_id', '=', 'goo.goo_id')
->where('sede_plus_minus', 2)
->where('sede_cid', $user_info->adm_cid)
->where('sede_superior_shop_id', $shop_id)
->whereIn('sede_goo_id', $sede_goo_id)
->groupBy('sede_goo_id')
->select(DB::raw('sum(sede_amount_price) as sede_amount_price, sum(sede_cost_amount_price) as sede_cost_amount_price, sum(sede_goo_quantity) as sede_goo_quantity, sede_goo_id'))
->paginate($this->show_count);
$returned_goods = json_decode(json_encode($goods->items()), true); //退货商品数据
$returned_goods_price = [];
if ($returned_goods) {
$returned_goods_price = array_column($returned_goods, null, 'sede_goo_id');
}
foreach ($list_items as $key => $value) {
// 计算公式利润 = (销售单价-成本单价)*销售数量 - (退货单价-成本单价)*退货数量
// 等价于 (销售总金额-销售成本总金额) - (退货总金额-退货成本总金额)
// 销售金额 = 销售总金额 - 销售成本总金额
$sell_price = $value->sede_amount_price - $value->sede_cost_amount_price;
$list_items[$key]->sales_return_quantity = 0; //退货总数量
$sales_return_price = 0;
$sales_sede_amount_price = 0; //退货总金额
if (isset($returned_goods_price[$value->sede_goo_id])) {
// 退货金额 = 退货总金额-退货成本总金额
$sales_return_price = $returned_goods_price[$value->sede_goo_id]['sede_amount_price'] - $returned_goods_price[$value->sede_goo_id]['sede_cost_amount_price'];
$sales_sede_amount_price = $returned_goods_price[$value->sede_goo_id]['sede_amount_price']; //退货总金额
$list_items[$key]->sales_return_quantity = $returned_goods_price[$value->sede_goo_id]['sede_goo_quantity'];
}
// 销售总金额-退货总金额
$sell_minus_sales = $value->sede_amount_price - $sales_sede_amount_price;
// 利润
$list_items[$key]->profit = $sell_price - $sales_return_price;
// 计算公式利率 = ((销售单价-成本单价)*销售数量 - (退货单价-成本单价)*退货数量)/(销售总金额-退货总金额)*100%
if ($sell_minus_sales) {
$list_items[$key]->rate = round($list_items[$key]->profit / $sell_minus_sales * 100, 2) . '%';
} else {
$list_items[$key]->rate = '0%';
}
}
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
} else {
$data_info['data'] = [];
}
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyStockSellStorageGoodsController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
// 财务系统 -- 进销存查询
class StockSellStorageGoodsController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 进销存查询列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyStockSellStorageGoodsController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('enters_sells_saves as ense')
->leftJoin('goods as goo', 'goo.goo_id', '=', 'ense.ense_goo_id')
->where('ense_shop_id', $shop_id)
->where('ense_goo_warehouse', $request['sssg_ware_id'])
->where('ense_goo_waretype', $request['sssg_waon_class'])
->where(function ($query) use ($search_data) { //商品名称
if (!empty($search_data['goo_name'])) {
$query->where('ense_goo_name', 'like', '%' . $search_data['goo_name'] . '%');
}
})
->where(function ($query) use ($search_data) { //检索编码
if (!empty($search_data['goo_goods_encode'])) {
$query->where('ense_goo_number', 'like', '%' . $search_data['goo_goods_encode'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo_bra_id', $search_data['goo_bra_id']);
}
}) //品牌id
->where(function ($query) use ($search_data) {
if (!empty($search_data['goo_cate_id'])) {
$query->where('goo_cate_id', $search_data['goo_cate_id']);
}
}) //品类id
// ->where(function ($query) use ($search_data) { //起始时间
// if (!empty($search_data['ense_time_start'])) {
// $query->where('ense_time', '>=', $search_data['ense_time_start'] . " 00:00:00");
// }
// })
->where(function ($query) use ($search_data) { //结束时间
if (!empty($search_data['ense_time_end'])) {
$query->where('ense_time', '<=', $search_data['ense_time_end'] . " 23:59:59");
}
})
->select('ense_goo_id')
->orderBy('ense_id', 'asc')
->groupBy('ense_goo_id')
->paginate($this->show_count);
// 查询出小于当前结束时间的所有商品id相关数据
$list_items = $list_data->items();
$list_goo_id = array_column($list_items, 'ense_goo_id'); //商品id
// 查询商品id相关进销存数据,查询时间段内的可以查到的商品数据
$list = DB::table('enters_sells_saves as ense')
->leftJoin('goods as goo', 'goo.goo_id', '=', 'ense.ense_goo_id')
->where('ense_shop_id', $shop_id)
->where('ense_goo_warehouse', $request['sssg_ware_id'])
->where('ense_goo_waretype', $request['sssg_waon_class'])
->whereIn('ense_goo_id', $list_goo_id)
->where(function ($query) use ($search_data) { //商品名称
if (!empty($search_data['goo_name'])) {
$query->where('ense_goo_name', 'like', '%' . $search_data['goo_name'] . '%');
}
})
->where(function ($query) use ($search_data) { //检索编码
if (!empty($search_data['goo_goods_encode'])) {
$query->where('ense_goo_number', 'like', '%' . $search_data['goo_goods_encode'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo_bra_id', $search_data['goo_bra_id']);
}
}) //品牌id
->where(function ($query) use ($search_data) {
if (!empty($search_data['goo_cate_id'])) {
$query->where('goo_cate_id', $search_data['goo_cate_id']);
}
}) //品类id
->where(function ($query) use ($search_data) { //起始时间
if (!empty($search_data['ense_time_start'])) {
$query->where('ense_time', '>=', $search_data['ense_time_start'] . " 00:00:00");
}
})
->where(function ($query) use ($search_data) { //结束时间
if (!empty($search_data['ense_time_end'])) {
$query->where('ense_time', '<=', $search_data['ense_time_end'] . " 23:59:59");
}
})
->select('ense_id', 'ense_goo_id', 'ense_goo_name', 'ense_goo_number', 'ense_goo_unit', 'ense_goo_specifications', 'ense_goo_waretype', 'ense_goo_warehouse', 'ense_new_inventory', 'ense_new_price', 'ense_new_amount', 'ense_end_inventory', 'ense_end_price', 'ense_end_amount', 'ense_out_num', 'ense_out_price', 'ense_out_amount', 'ense_in_num', 'ense_in_price', 'ense_in_amount', 'ense_order_number', 'ense_out_in', 'ense_type', 'ense_time')
->orderBy('ense_id', 'asc')
->get()->toArray();
$get_goo_id = array_unique(array_column($list, 'ense_goo_id')); //已经查询出数据的商品id
// 在选择的时间段内没有查询到的商品id数据
$nonentity_goo_id = array_diff($list_goo_id, $get_goo_id);
$nonentity_list = [];
if ($nonentity_goo_id) {
// 上面时间段没有查询到商品数据的,查询距离开始时间最近的一条数据
foreach ($nonentity_goo_id as $key => $value) {
$find_enters = DB::table('enters_sells_saves')
->where('ense_shop_id', $shop_id)
->where('ense_goo_warehouse', $request['sssg_ware_id'])
->where('ense_goo_waretype', $request['sssg_waon_class'])
->where('ense_goo_id', $value)
->where('ense_time', '<', $search_data['ense_time_start'] . " 00:00:00")
->select('ense_id', 'ense_goo_id', 'ense_goo_name', 'ense_goo_number', 'ense_goo_unit', 'ense_goo_specifications', 'ense_goo_waretype', 'ense_goo_warehouse', 'ense_new_inventory', 'ense_new_price', 'ense_new_amount', 'ense_end_inventory', 'ense_end_price', 'ense_end_amount', 'ense_out_num', 'ense_out_price', 'ense_out_amount', 'ense_in_num', 'ense_in_price', 'ense_in_amount', 'ense_order_number', 'ense_out_in', 'ense_type', 'ense_time')
->orderBy('ense_id', 'desc')
->first();
// 查询的最近的一条数据,因为没有发生出入库记录,所以月入、月出、月调数据都为0
// 期初数据等于上一次期末数据
// 因为时间段内没有查出数据,这个数据就是上一次的数据
// 所以这个的期初数据等于期末数据
$find_enters->ense_new_inventory = $find_enters->ense_end_inventory;
$find_enters->ense_new_price = $find_enters->ense_end_price;
$find_enters->ense_new_amount = $find_enters->ense_end_amount;
$find_enters->ense_out_num = 0;
$find_enters->ense_out_price = 0;
$find_enters->ense_out_amount = 0;
$find_enters->ense_in_num = 0;
$find_enters->ense_in_price = 0;
$find_enters->ense_in_amount = 0;
$nonentity_list[] = (array)$find_enters;
}
}
$list = json_decode(json_encode($list), true);
// 合并数组
$list = array_merge($list, $nonentity_list);
$return_data = []; //进销存返回数据
if ($list) {
// 查询仓库名称
$warehouse_name = DB::table('warehouse')
->where('ware_id', $request['sssg_ware_id'])
->value('ware_name');
// 查询仓库类别显示名称
$warehouse_class = DB::table('warehouse_class')
->where('wacl_cid', $user_info->adm_cid)
->where('wacl_superior_shop_id', $shop_id)
->where('wacl_class_numerical', $request['sssg_waon_class'])
->value('wacl_class_name');
// 根据商品id查询商品数据
$find_goo_data = DB::table('goods')
->whereIn('goo_id', $list_goo_id)
->select('goo_bra_name', 'goo_brse_id', 'goo_class', 'goo_id')
->get()->toArray();
$goo_data = array_column($find_goo_data, null, 'goo_id');
$goo_brse_id = array_column($find_goo_data, 'goo_brse_id', 'goo_id');
// 查询系列数据
$find_brse_id = array_column($find_goo_data, 'goo_brse_id');
$brse_data = DB::table('brand_serie')
->whereIn('brse_id', $find_brse_id)
->pluck('brse_name', 'brse_id')
->toArray();
$list_adjust = []; //重新调整后的数据
foreach ($list as $key => $value) {
// 判断进销存商品id是否存在
if (isset($list_adjust[$value['ense_goo_id']])) {
$list_adjust[$value['ense_goo_id']]['ense_end_inventory'] = $value['ense_end_inventory']; //结余库存
$list_adjust[$value['ense_goo_id']]['ense_end_price'] = sprintf("%.4f", $value['ense_end_price']); //期末平均价
$list_adjust[$value['ense_goo_id']]['ense_end_amount'] = sprintf("%.4f", $value['ense_end_amount']); //结余成本
// 判断是否为调拨单
if (substr($value['ense_order_number'], 0, 2) == 'DB') {
$list_adjust[$value['ense_goo_id']]['mouthnums'] = $list_adjust[$value['ense_goo_id']]['mouthnums'] + $value['ense_in_num'] - $value['ense_out_num'];
$list_adjust[$value['ense_goo_id']]['mouthprice'] = sprintf("%.4f", $list_adjust[$value['ense_goo_id']]['mouthprice'] + $value['ense_in_amount'] - $value['ense_out_amount']);
} else {
// ense_out_num 月出数量
$list_adjust[$value['ense_goo_id']]['ense_out_num'] = $value['ense_out_num'] + $list_adjust[$value['ense_goo_id']]['ense_out_num'];
// ense_out_amount 月出成本
$list_adjust[$value['ense_goo_id']]['ense_out_amount'] = sprintf("%.4f", $value['ense_out_amount'] + $list_adjust[$value['ense_goo_id']]['ense_out_amount']);
// ense_in_num 月入数量
$list_adjust[$value['ense_goo_id']]['ense_in_num'] = $value['ense_in_num'] + $list_adjust[$value['ense_goo_id']]['ense_in_num'];
// ense_in_amount 月入成本
$list_adjust[$value['ense_goo_id']]['ense_in_amount'] = sprintf("%.4f", $value['ense_in_amount'] + $list_adjust[$value['ense_goo_id']]['ense_in_amount']);
}
} else {
// 判断是否为调拨单
if (substr($value['ense_order_number'], 0, 2) == 'DB') {
// 调拨单处理
// 月调数量 = 月入数量 - 月出数量
$value['mouthnums'] = $value['ense_in_num'] - $value['ense_out_num']; //月调数量
// 月调成本 = 月入成本 - 月出成本
$value['mouthprice'] = sprintf("%.4f", $value['ense_in_amount'] - $value['ense_out_amount']); //月调成本
$value['ense_out_num'] = 0; //月出数量
$value['ense_out_amount'] = 0; //月出成本
$value['ense_in_num'] = 0; //月入数量
$value['ense_in_amount'] = 0; //月入成本
} else {
$value['mouthnums'] = 0; //月调数量
$value['mouthprice'] = 0; //月调成本
}
$value['ense_goo_waretype'] = $warehouse_class;
$value['ense_goo_warehouse'] = $warehouse_name;
$list_adjust[$value['ense_goo_id']] = $value;
}
}
$i = 0;
foreach ($list_adjust as $key => $value) {
$return_data[$i] = $value;
// 平均价差异金额 = 期末平均价 - 期初平均价
$new_end_price = sprintf("%.0f", $value['ense_end_price'] - $value['ense_new_price']); //期初平均价
$return_data[$i]['new_end_price'] = $new_end_price;
// ense_out_num 月出数量
if ($value['ense_out_num'] == '0') {
$return_data[$i]['ense_out_price'] = '0'; //月出平均价
} else {
// 月出平均价 = 月出成本 / 月出库存
$return_data[$i]['ense_out_price'] = sprintf("%.4f", $value['ense_out_amount'] / $value['ense_out_num']);
}
// ense_in_num 月入数量
if ($value['ense_in_num'] == '0') {
$return_data[$i]['ense_in_price'] = '0'; //月入平均价
} else {
// 月入平均价 = 月入成本 / 月入数量
$return_data[$i]['ense_in_price'] = sprintf("%.4f", $value['ense_in_amount'] / $value['ense_in_num']);
}
$i++;
}
// 处理商品品牌系列
foreach ($return_data as $key => $value) {
if (!in_array($user_info->adm_shop_id, config('apisystem.NO_BRSND_SERIE_SHOP')) && isset($goo_brse_id[$value['ense_goo_id']]) && isset($brse_data[$goo_brse_id[$value['ense_goo_id']]])) {
if (!empty($goo_brse_id[$value['ense_goo_id']])) {
// 显示系列名称
if ($goo_data[$value['ense_goo_id']]->goo_class == 2) {
$return_data[$key]['ense_goo_name'] = $brse_data[$goo_brse_id[$value['ense_goo_id']]] . ' ' . $value['ense_goo_name'];
} else {
if (!in_array($user_info->adm_shop_id, config('apisystem.NO_SELF_GOODS_SHOP'))) {
$return_data[$key]['ense_goo_name'] = $brse_data[$goo_brse_id[$value['ense_goo_id']]] . ' ' . $value['ense_goo_name'];
unset($goo_brse_id[$value['ense_goo_id']]);
}
}
unset($goo_brse_id[$value['ense_goo_id']]);
}
}
// 显示品牌名称
if (!in_array($user_info->adm_shop_id, config('apisystem.NO_BRAND_SHOP')) && isset($goo_data[$value['ense_goo_id']])) {
if ($goo_data[$value['ense_goo_id']]->goo_class == 2) {
$return_data[$key]['ense_goo_name'] = $goo_data[$value['ense_goo_id']]->goo_bra_name . ' ' . $return_data[$key]['ense_goo_name'];
} else {
if (!in_array($user_info->adm_shop_id, config('apisystem.NO_SELF_GOODS_SHOP'))) {
$return_data[$key]['ense_goo_name'] = $goo_data[$value['ense_goo_id']]->goo_bra_name . ' ' . $return_data[$key]['ense_goo_name'];
}
}
}
}
}
// 查询所有的商品id
$all_goo_id = DB::table('enters_sells_saves as ense')
->leftJoin('goods as goo', 'goo.goo_id', '=', 'ense.ense_goo_id')
->where('ense_shop_id', $shop_id)
->where('ense_goo_warehouse', $request['sssg_ware_id'])
->where('ense_goo_waretype', $request['sssg_waon_class'])
->where(function ($query) use ($search_data) { //商品名称
if (!empty($search_data['goo_name'])) {
$query->where('ense_goo_name', 'like', '%' . $search_data['goo_name'] . '%');
}
})
->where(function ($query) use ($search_data) { //检索编码
if (!empty($search_data['goo_goods_encode'])) {
$query->where('ense_goo_number', 'like', '%' . $search_data['goo_goods_encode'] . '%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo_bra_id', $search_data['goo_bra_id']);
}
}) //品牌id
->where(function ($query) use ($search_data) {
if (!empty($search_data['goo_cate_id'])) {
$query->where('goo_cate_id', $search_data['goo_cate_id']);
}
}) //品类id
// ->where(function ($query) use ($search_data) { //起始时间
// if (!empty($search_data['ense_time_start'])) {
// $query->where('ense_time', '>=', $search_data['ense_time_start'] . " 00:00:00");
// }
// })
->where(function ($query) use ($search_data) { //结束时间
if (!empty($search_data['ense_time_end'])) {
$query->where('ense_time', '<=', $search_data['ense_time_end'] . " 23:59:59");
}
})
->select('ense_goo_id')
->orderBy('ense_id', 'asc')
->groupBy('ense_goo_id')
->get()->toArray();
$all_goo_id = array_unique(array_column($all_goo_id, 'ense_goo_id'));
// 查询合计数据
$statistics = DB::table('enters_sells_saves as ense')
->leftJoin('goods as goo', 'goo.goo_id', '=', 'ense.ense_goo_id')
->where('ense_shop_id', $shop_id)
->where('ense_goo_warehouse', $request['sssg_ware_id'])
->where('ense_goo_waretype', $request['sssg_waon_class'])
->where(function ($query) use ($search_data) { //商品名称
if (!empty($search_data['goo_name'])) {
$query->where('ense_goo_name', 'like', '%' . $search_data['goo_name'] . '%');
}
})
->where(function ($query) use ($search_data) { //检索编码
if (!empty($search_data['goo_goods_encode'])) {
$query->where('ense_goo_number', 'like', '%' . $search_data['goo_goods_encode'] . '%');
}
})
->where(function ($query) use ($search_data) { //品牌id
if (!empty($search_data['goo_bra_id'])) {
$query->where('goo.goo_bra_id', $search_data['goo_bra_id']);
}
})
->where(function ($query) use ($search_data) { //品类id
if (!empty($search_data['goo_cate_id'])) {
$query->where('goo_cate_id', $search_data['goo_cate_id']);
}
})
->where(function ($query) use ($search_data) { //起始时间
if (!empty($search_data['ense_time_start'])) {
$query->where('ense_time', '>=', $search_data['ense_time_start'] . " 00:00:00");
}
})
->where(function ($query) use ($search_data) { //结束时间
if (!empty($search_data['ense_time_end'])) {
$query->where('ense_time', '<=', $search_data['ense_time_end'] . " 23:59:59");
}
})
->select('ense_id', 'ense_goo_id', 'ense_new_inventory', 'ense_new_price', 'ense_new_amount', 'ense_end_inventory', 'ense_end_price', 'ense_end_amount', 'ense_out_num', 'ense_out_price', 'ense_out_amount', 'ense_in_num', 'ense_in_price', 'ense_in_amount', 'ense_order_number')
->orderBy('ense_id', 'asc')
->get()->toArray();
$statistics_goo_id = array_unique(array_column($statistics, 'ense_goo_id'));
// 在选择的时间段内没有查询到的商品id数据
$nonentity_goo_id = array_diff($all_goo_id, $statistics_goo_id);
$nonentity_list = [];
if ($nonentity_goo_id) {
// 上面时间段没有查询到商品数据的,查询距离开始时间最近的一条数据
foreach ($nonentity_goo_id as $key => $value) {
$find_enters = DB::table('enters_sells_saves')
->where('ense_shop_id', $shop_id)
->where('ense_goo_warehouse', $request['sssg_ware_id'])
->where('ense_goo_waretype', $request['sssg_waon_class'])
->where('ense_goo_id', $value)
->where('ense_time', '<', $search_data['ense_time_start'] . " 00:00:00")
->select('ense_id', 'ense_goo_id', 'ense_new_inventory', 'ense_new_price', 'ense_new_amount', 'ense_end_inventory', 'ense_end_price', 'ense_end_amount', 'ense_out_num', 'ense_out_price', 'ense_out_amount', 'ense_in_num', 'ense_in_price', 'ense_in_amount', 'ense_order_number')
->orderBy('ense_id', 'desc')
->first();
// 查询的最近的一条数据,因为没有发生出入库记录,所以月入、月出、月调数据都为0
// 期初数据等于上一次期末数据
// 因为时间段内没有查出数据,这个数据就是上一次的数据
// 所以这个的期初数据等于期末数据
$find_enters->ense_new_inventory = $find_enters->ense_end_inventory;
$find_enters->ense_new_price = $find_enters->ense_end_price;
$find_enters->ense_new_amount = $find_enters->ense_end_amount;
$find_enters->ense_out_num = 0;
$find_enters->ense_out_price = 0;
$find_enters->ense_out_amount = 0;
$find_enters->ense_in_num = 0;
$find_enters->ense_in_price = 0;
$find_enters->ense_in_amount = 0;
$nonentity_list[] = (array)$find_enters;
}
}
$statistics_data = array();
$statistics_data['mouthnums'] = '0';
$statistics_data['mouthprice'] = '0';
$statistics = json_decode(json_encode($statistics), true);
// 合并数组
$statistics = array_merge($statistics, $nonentity_list);
$isarray = array();
foreach ($statistics as $k => $v) {
if (isset($isarray[$v['ense_goo_id']])) {
$isarray[$v['ense_goo_id']]['ense_end_inventory'] = $v['ense_end_inventory'];
$isarray[$v['ense_goo_id']]['ense_end_price'] = $v['ense_end_price'];
$isarray[$v['ense_goo_id']]['ense_end_amount'] = $v['ense_end_amount'];
if (substr($v['ense_order_number'], 0, 2) != 'DB') {
if (!is_numeric($v['ense_out_amount'])) {
$v['ense_out_amount'] = substr($v['ense_out_amount'], 1, strlen($v['ense_out_price']) - 1);
}
if (!is_numeric($v['ense_out_price'])) {
$v['ense_out_price'] = substr($v['ense_out_price'], 1, strlen($v['ense_out_price']) - 1);
}
$isarray[$v['ense_goo_id']]['ense_out_num'] = $isarray[$v['ense_goo_id']]['ense_out_num'] + $v['ense_out_num'];
$isarray[$v['ense_goo_id']]['ense_out_amount'] = $isarray[$v['ense_goo_id']]['ense_out_amount'] + $v['ense_out_amount'];
$isarray[$v['ense_goo_id']]['ense_in_num'] = $isarray[$v['ense_goo_id']]['ense_in_num'] + $v['ense_in_num'];
$isarray[$v['ense_goo_id']]['ense_in_amount'] = $isarray[$v['ense_goo_id']]['ense_in_amount'] + $v['ense_in_amount'];
} else {
$statistics_data['mouthnums'] = sprintf("%.4f", $statistics_data['mouthnums'] + $v['ense_in_num'] - $v['ense_out_num']);
$statistics_data['mouthprice'] = sprintf("%.4f", $statistics_data['mouthprice'] + $v['ense_in_amount'] - $v['ense_out_amount']);
}
} else {
if (substr($v['ense_order_number'], 0, 2) == 'DB') {
$statistics_data['mouthnums'] = sprintf("%.4f", $statistics_data['mouthnums'] + $v['ense_in_num'] - $v['ense_out_num']);
$statistics_data['mouthprice'] = sprintf("%.4f", $statistics_data['mouthprice'] + $v['ense_in_amount'] - $v['ense_out_amount']);
$v['ense_out_num'] = 0;
$v['ense_out_amount'] = 0;
$v['ense_in_num'] = 0;
$v['ense_in_amount'] = 0;
}
$isarray[$v['ense_goo_id']] = $v;
$isarray[$v['ense_goo_id']]['ense_new_inventory'] = $v['ense_new_inventory'];
$isarray[$v['ense_goo_id']]['ense_new_price'] = $v['ense_new_price'];
$isarray[$v['ense_goo_id']]['ense_new_amount'] = $v['ense_new_amount'];
$isarray[$v['ense_goo_id']]['ense_end_inventory'] = $v['ense_end_inventory'];
$isarray[$v['ense_goo_id']]['ense_end_price'] = $v['ense_end_price'];
$isarray[$v['ense_goo_id']]['ense_end_amount'] = $v['ense_end_amount'];
}
}
$statistics_data['ense_new_inventory'] = 0;
$statistics_data['ense_new_price'] = 0;
$statistics_data['ense_new_amount'] = 0;
$statistics_data['ense_end_inventory'] = 0;
$statistics_data['ense_end_price'] = 0;
$statistics_data['ense_end_amount'] = 0;
$statistics_data['ense_out_num'] = 0;
$statistics_data['ense_out_amount'] = 0;
$statistics_data['ense_in_num'] = 0;
$statistics_data['ense_in_amount'] = 0;
foreach ($isarray as $k => $v) {
$statistics_data['ense_new_inventory'] = $statistics_data['ense_new_inventory'] + $v['ense_new_inventory'];
$statistics_data['ense_new_price'] = sprintf("%.4f", $statistics_data['ense_new_price'] + $v['ense_new_price']);
$statistics_data['ense_new_amount'] = sprintf("%.4f", $statistics_data['ense_new_amount'] + $v['ense_new_amount']);
$statistics_data['ense_end_inventory'] = $statistics_data['ense_end_inventory'] + $v['ense_end_inventory'];
$statistics_data['ense_end_price'] = sprintf("%.4f", $statistics_data['ense_end_price'] + $v['ense_end_price']);
$statistics_data['ense_end_amount'] = sprintf("%.4f", $statistics_data['ense_end_amount'] + $v['ense_end_amount']);
$statistics_data['ense_out_num'] = $statistics_data['ense_out_num'] + $v['ense_out_num'];
$statistics_data['ense_out_amount'] = sprintf("%.4f", $statistics_data['ense_out_amount'] + $v['ense_out_amount']);
$statistics_data['ense_in_num'] = $statistics_data['ense_in_num'] + $v['ense_in_num'];
$statistics_data['ense_in_amount'] = sprintf("%.4f", $statistics_data['ense_in_amount'] + $v['ense_in_amount']);
}
if ($statistics_data['ense_in_num'] == '0') {
$statistics_data['ense_in_price'] = '0';
} else {
$statistics_data['ense_in_price'] = sprintf("%.4f", $statistics_data['ense_in_amount'] / $statistics_data['ense_in_num']);
}
if ($statistics_data['ense_out_num'] == '0') {
$statistics_data['ense_out_price'] = '0';
} else {
$statistics_data['ense_out_price'] = sprintf("%.4f", $statistics_data['ense_out_amount'] / $statistics_data['ense_out_num']);
}
if ($statistics_data['ense_end_inventory'] == '0') {
$statistics_data['ense_end_price'] = '0';
} else {
$statistics_data['ense_end_price'] = sprintf("%.4f", $statistics_data['ense_end_amount'] / $statistics_data['ense_end_inventory']);
}
if ($statistics_data['ense_new_inventory'] == '0') {
$statistics_data['ense_new_price'] = '0';
} else {
$statistics_data['ense_new_price'] = sprintf("%.4f", $statistics_data['ense_new_amount'] / $statistics_data['ense_new_inventory']);
}
$hzce = sprintf("%.0f", $statistics_data['ense_end_price'] - $statistics_data['ense_new_price']);
$statistics_data['new_end_price'] = $hzce;
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $return_data; //返回数据
$data_info['statistics_data'] = $statistics_data; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if ($list_data) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'暂无数据']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyStockingSellingController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
use App\Http\Models\Api\StockingSelling;
use App\Http\Models\Api\Export;
class StockingSellingController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
//进销存查询列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyStockingSellingController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$input = $request->all();
$list_data = DB::table('stocking_selling')
->where('stse_cid', $user_info->adm_cid)
->where('stse_superior_id', $shop_id)
//年
->where(function($query) use($input) {
if (!empty($input['stse_year'])) {
$query->where('stse_year', $input['stse_year']);
}
})
//月
->where(function($query) use($input) {
if (!empty($input['stse_month'])) {
$query->where('stse_month', $input['stse_month']);
}
})
//门店id
->where(function($query) use($input) {
if (!empty($input['stse_shop_id'])) {
$query->where('stse_shop_id', $input['stse_shop_id']);
}
})
//仓库id
->where(function($query) use($input) {
if (!empty($input['stse_ware_id'])) {
$query->where('stse_ware_id', $input['stse_ware_id']);
}
})
->select('stse_id','stse_shop_name','stse_year','stse_month','stse_ware_id','stse_ware_name','stse_ware_in','stse_ware_out','stse_initial_stock','stse_closing_stock','stse_initial_cost','stse_closing_cost')
->orderBy('stse_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
if(!empty($input['stse_year']) || !empty($input['stse_month']) || !empty($input['stse_shop_id']) || !empty($input['stse_ware_id'])){
$stics = DB::table('stocking_selling')
->where('stse_cid', $user_info->adm_cid)
->where('stse_superior_id', $shop_id)
->where(function($query) use($input) {
if (!empty($input['stse_year'])) {
$query->where('stse_year', $input['stse_year']);
}
})
//月
->where(function($query) use($input) {
if (!empty($input['stse_month'])) {
$query->where('stse_month', $input['stse_month']);
}
})
//门店id
->where(function($query) use($input) {
if (!empty($input['stse_shop_id'])) {
$query->where('stse_shop_id', $input['stse_shop_id']);
}
})
//仓库id
->where(function($query) use($input) {
if (!empty($input['stse_ware_id'])) {
$query->where('stse_ware_id', $input['stse_ware_id']);
}
})
->select(DB::raw('sum(stse_ware_in) as in_ware,sum(stse_ware_out) as out_ware,sum(stse_initial_stock) as initial_stock,sum(stse_closing_stock) as closing_stock'))
->first();
// $statistics['year'] = date('Y');
// $statistics['month'] = date('m');
$statistics['in_ware'] =isset($stics->in_ware) ? $stics->in_ware :0;//入库
$statistics['out_ware'] =isset($stics->out_ware) ? $stics->out_ware :0;//出库
$statistics['initial_stock'] =isset($stics->initial_stock) ? $stics->initial_stock:0;//期初库存
$statistics['closing_stock'] =isset($stics->closing_stock) ? $stics->closing_stock:0;//期末库存
}else{
$statistics = '';
}
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button,'statistics'=>$statistics]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 进销存查询列表详情
public function detail(Request $request)
{
// 验证数据
$verify_data = new VerifyStockingSellingController;
$error_message = $verify_data->detailValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$input = $request->all();
$list_data = DB::table('stocking_selling_goods')
->where('sego_cid', $user_info->adm_cid)
// ->where('sego_shop_id', $user_info->adm_shop_id)
->where('sego_stse_id', $input['sego_stse_id'])
//商品名称
->where(function($query) use($input) {
if (!empty($input['sego_goo_name'])) {
$query->where('sego_goo_name', 'like',$input['sego_goo_name'].'%');
}
})
//商品编号
->where(function($query) use($input) {
if (!empty($input['sego_goo_encode'])) {
$query->where('sego_goo_encode', $input['sego_goo_encode']);
}
})
->select('sego_id','sego_bra_id','sego_goo_id','sego_goo_name','sego_goo_encode','sego_initial_inventory','sego_closing_inventory','sego_closing_costing','sego_early_costing','sego_costing as sego_in_costing','sego_in_num','sego_out_num')
->orderBy('sego_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
if (!empty($data_info['data'])) {
$sego_bra_id = [];
foreach ($data_info['data'] as $key => $value) {
$sego_bra_id[] = $value->sego_bra_id;
if(empty($value->sego_bra_id)){
$data_info['data'][$key]->sego_bra_id = '';
}
}
$res = DB::table('brand')->whereIn('bra_id',$sego_bra_id)->get(['bra_id','bra_name']);
$data_info['brand_data'] = $res;
}else{
$data_info['brand_data'] = '';
}
// $StockingSelling = new StockingSelling;
// if($request['type'] == 1){
// $goods_id = [1,2];
// $num = [100,100];
// $costing = 10;
// $ware_id = 5;
// $type = 1;
// $StockingSelling->purchase($user_info,$goods_id,$num,$costing,$ware_id,$type);
// }
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
//导出
public function indexExport(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$input = $request->all();
$list_data = DB::table('stocking_selling')
->where('stse_cid', $user_info->adm_cid)
->where('stse_superior_id', $shop_id)
//年
->where(function($query) use($input) {
if (!empty($input['stse_year'])) {
$query->where('stse_year', $input['stse_year']);
}
})
//月
->where(function($query) use($input) {
if (!empty($input['stse_month'])) {
$query->where('stse_month', $input['stse_month']);
}
})
//门店id
->where(function($query) use($input) {
if (!empty($input['stse_shop_id'])) {
$query->where('stse_shop_id', $input['stse_shop_id']);
}
})
//仓库id
->where(function($query) use($input) {
if (!empty($input['stse_ware_id'])) {
$query->where('stse_ware_id', $input['stse_ware_id']);
}
})
->select('stse_shop_name','stse_year','stse_month','stse_ware_name','stse_ware_in','stse_ware_out','stse_initial_stock','stse_closing_stock','stse_initial_cost','stse_closing_cost')
->orderBy('stse_id', 'desc')
->get();
if(empty($list_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
if(count($list_data) > 10000){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'不能导出大于10000的数据']);
}
// 将对象转化为数组
$list_data = json_decode(json_encode($list_data),true);
foreach ($list_data as $key => $value) {
if(!empty($value['stse_closing_cost'])){
$list_data[$key]['stse_closing_cost'] = $value['stse_closing_cost'] / 100;
}
if(!empty($value['stse_initial_cost'])){
$list_data[$key]['stse_initial_cost'] = $value['stse_initial_cost'] / 100;
}
}
$pathName = storage_path()."/app/public/excel";//获取上传excel路径
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName,0775,true);
chmod($pathName,0775);
}
$streamFileRand = time() . rand(10000,99999).'.xls';//
// 产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
$streamFilename = $pathName . '/' .$streamFileRand;
$where['action_name'] = '进销存查询'; //
$where['field_name'] = ['门店名称','年份','月份','仓库名称','入库数量','出库数量','期初库存','期末库存','期初成本(元)','期末成本(元)'];
// 调用导出的公共方法
export::publicExport(
$streamFilename, //路径
$where, //sheet名及其每一行的标题
$list_data //导出数据
);
// 判断文件是否存在 存在则成功 不存在则失败
if(file_exists($pathName))
{
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>'storage/excel/'.$streamFileRand]);
}else{
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'导出失败']);
}
}
//详情导出
public function detailExport(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$input = $request->all();
if(empty($request['sego_stse_id'])){
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误']);
}
$list_data = DB::table('stocking_selling_goods')
->where('sego_cid', $user_info->adm_cid)
// ->where('sego_shop_id', $user_info->adm_shop_id)
->where('sego_stse_id', $request['sego_stse_id'])
//商品名称
->where(function($query) use($input) {
if (!empty($input['sego_goo_name'])) {
$query->where('sego_goo_name', $input['sego_goo_name']);
}
})
//商品编号
->where(function($query) use($input) {
if (!empty($input['sego_goo_encode'])) {
$query->where('sego_goo_encode', $input['sego_goo_encode']);
}
})
->select('sego_bra_id','sego_goo_name','sego_goo_encode','sego_initial_inventory',
'sego_early_costing', 'sego_costing','sego_in_num',
'sego_out_num','sego_closing_inventory')
->orderBy('sego_id', 'desc')
->get();
if(empty($list_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
if(count($list_data) > 10000){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'不能导出大于10000的数据']);
}
// 将对象转化为数组
$list_data = json_decode(json_encode($list_data),true);
$sego_bra_id = [];
foreach ($list_data as $key => $value) {
$sego_bra_id[] = $value['sego_bra_id'];
if(!empty($value['sego_closing_costing'])){
$list_data[$key]['sego_closing_costing'] = $value['sego_closing_costing'] / 100;
}
if(!empty($value['sego_early_costing'])){
$list_data[$key]['sego_early_costing'] = $value['sego_early_costing'] / 100;
}
if(!empty($value['sego_costing'])){
$list_data[$key]['sego_costing'] = $value['sego_costing'] / 100;
}
}
$brand = DB::table('brand')->whereIn('bra_id',$sego_bra_id)->pluck('bra_name','bra_id')->toArray();
foreach ($list_data as $key => $value) {
if($value['sego_bra_id'] == 0){
$list_data[$key]['sego_bra_id'] = '';
}else{
$list_data[$key]['sego_bra_id'] = $brand[$value['sego_bra_id']];
}
}
$pathName = storage_path()."/app/public/excel";//获取上传excel路径
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName,0775,true);
chmod($pathName,0775);
}
$streamFileRand = time() . rand(10000,99999).'.xls';//
// 产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
$streamFilename = $pathName . '/' .$streamFileRand;
$where['action_name'] = '进销存查询'; //
$where['field_name'] = ['品牌','商品名称','检索编码','期初库存','期初成本','成本','入库数量','出库数量','期末库存'];
// 调用导出的公共方法
export::publicExport(
$streamFilename, //路径
$where, //sheet名及其每一行的标题
$list_data //导出数据
);
// 判断文件是否存在 存在则成功 不存在则失败
if(file_exists($pathName))
{
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>'storage/excel/'.$streamFileRand]);
}else{
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'导出失败']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyVoucherReceiptsController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
use Psy\VarDumper\Dumper;
use App\Http\Models\Api\YongYou;
use App\Http\Models\Api\YongYous;
// 财务系统 -- 凭证列表
class VoucherReceiptsController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyVoucherReceiptsController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('voucher_receipts as vore')
->where('vore_cid', $user_info->adm_cid)
->where('vore_superior_shop_id', $shop_id)
->where(function ($query) use ($search_data) { //订单/工单/采购单号
if (!empty($search_data['vore_order_number'])) {
$query->where('vore_ord_number', 'like', '%' . $search_data['vore_order_number'] . '%')
->orwhere('vore_wor_number', 'like', '%' . $search_data['vore_order_number'] . '%');
}
})
->where(function ($query) use ($search_data) { //单位类型1会员零售2客户单位3速电派单
if (!empty($search_data['vore_type'])) {
$query->where('vore_type', $search_data['vore_type']);
}
})
->where(function ($query) use ($search_data) { //客户单位
if (!empty($search_data['vore_channel_unit'])) {
$query->where('vore_channel_unit', 'like', '%' . $search_data['vore_channel_unit'] . '%');
}
})
->where(function ($query) use ($search_data) { //状态1未同步2已同步
if (!empty($search_data['vore_state'])) {
$query->where('vore_state', $search_data['vore_state']);
}
})
->where(function ($query) use ($search_data) { //创建时间
// 如果选择开始时间并且选择结束时间
if (!empty($search_data['create_time_start']) && !empty($search_data['create_time_end'])) {
$query->whereBetween('vore_create_time', [$search_data['create_time_start'], $search_data['create_time_end'] . ' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['create_time_start'])) {
$query->where('vore_create_time', '>=', $search_data['create_time_start']);
} else {
// 如果选择结束时间
if (!empty($search_data['create_time_end'])) {
$query->where('vore_create_time', '<=', $search_data['create_time_end'] . ' 23:59:59');
}
}
}
})
->where(function ($query) use ($search_data) { //单号类型
if (!empty($search_data['vore_order_type'])) {
$query->where('vore_order_type', $search_data['vore_order_type']);
}
})
->where(function ($query) use ($search_data) { //客户单位id
if (!empty($search_data['vore_client_id'])) {
$query->where('vore_client_id', $search_data['vore_client_id']);
}
})
->where(function ($query) use ($search_data) { //买家类型:1会员零售2客户单位3速电派单
if (!empty($search_data['vore_type'])) {
$query->where('vore_type', $search_data['vore_type']);
}
})
->where(function ($query) use ($search_data) { //订单类型:1服务单 2销售单 3换货单 4退货单 5发货单 6结清单 7救援单
if (!empty($search_data['vore_service_type'])) {
$query->where('vore_service_type', $search_data['vore_service_type']);
}
})
->select('vore_id', 'vore_order_type', 'vore_wor_id', 'vore_wor_number', 'vore_ord_id', 'vore_ord_number', 'vore_actual_price', 'vore_collection_price', 'vore_recycle_price', 'vore_plus_minus', 'vore_type', 'vore_channel_unit', 'vore_create_time', 'vore_state', 'vore_early_costing', 'vore_client_id', 'vore_service_type')
->orderBy('vore_create_time', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
$vore_id = array_column($list_items, 'vore_id'); //凭证id
$ord_id = array_column($list_items, 'vore_ord_id'); //订单id
// 查询凭证借贷表信息
$volo_data = DB::table('voucher_loan')
->whereIn('volo_vore_id', $vore_id)
->select('volo_vore_id', 'volo_type', 'volo_borrow_subject', 'volo_borrow_subject_name', 'volo_borrow_price', 'volo_loan_subject', 'volo_loan_subject_name', 'volo_loan_price', 'volo_borrow_costing', 'volo_borrow_costing_subject', 'volo_borrow_costing_name', 'volo_loan_costing', 'volo_loan_costing_subject', 'volo_loan_costing_name')
->get();
// 查询备注信息
$order_reamrks = DB::table('order_remarks')
->whereIn('orre_ord_id', $ord_id)
->select('orre_create_adm_name', 'orre_content', 'orre_time', 'orre_ord_id')
->orderby('orre_id', 'desc')
->get();
// 查询客户单位
$channel = DB::table('channel_unit')
->where('chun_shop_id', $shop_id)
->where('chun_state', '1')
->select('chun_id', 'chun_unit_name')
->get();
$channel = json_decode(json_encode($channel), true);
foreach ($channel as $k => $v) {
$channel_name[$v['chun_id']] = $v['chun_unit_name'];
}
foreach ($list_items as $key => $value) {
// 客户单位名称
if (isset($channel_name[$value->vore_client_id])) {
$list_items[$key]->vore_channel_unit = $channel_name[$value->vore_client_id];
} else {
$list_items[$key]->vore_channel_unit = $value->vore_channel_unit;
}
}
} else {
$volo_data = [];
$order_reamrks = [];
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['volo_data'] = $volo_data; //订单商品数据
$data_info['order_reamrks'] = $order_reamrks; //订单商品数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if ($list_data) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'暂无数据']);
}
}
// 详情
public function info(Request $request)
{
// 验证数据
$verify_data = new VerifyVoucherReceiptsController;
$error_message = $verify_data->infoValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 查找凭证列表
$find_vore_data = DB::table('voucher_receipts')
->where('vore_id', $request['vore_id'])
->select('vore_order_type', 'vore_wor_id', 'vore_wor_number', 'vore_ord_id', 'vore_ord_number')
->first();
// vore_order_type 单号类型1.订单2.工单3.采购单4.销售单
if ($find_vore_data->vore_order_type == 1) { //订单详情
// 查询服务项目id
$info = DB::table('order as ord')
->leftjoin('order_client as orcl', 'orcl.orcl_ord_id', '=', 'ord.ord_id')
->where('ord_id', $find_vore_data->vore_ord_id)
->select('ord_service_sepr_id', 'orcl_rescue_service_price')
->first();
// 根据服务项目id,查询服务名称
if ($info->ord_service_sepr_id != '0') {
$sepr_data = DB::table('service_project')
->where('sepr_id', $info->ord_service_sepr_id)
->select('sepr_name', 'sepr_order_money')
->first();
$info->ord_service_sepr_name = $sepr_data->sepr_name;
$info->sepr_order_money = $info->orcl_rescue_service_price;
unset($info->ord_service_sepr_id);
unset($info->orcl_rescue_service_price);
} else {
unset($info->ord_service_sepr_id);
$info = '';
}
// 查询商品信息
$goods_data = DB::table('order_goods')
->where('orgo_ord_id', $find_vore_data->vore_ord_id)
->where('orgo_state', '!=', 2)
->select('orgo_goo_name', 'orgo_goo_goods_encode', 'orgo_goo_quantity', 'orgo_goo_price', 'orgo_is_recycle', 'orgo_can_assign_quantity', 'orgo_collection_price', 'orgo_goo_inventory', 'orgo_state', 'orgo_goo_type', 'orgo_recycle_price', 'orgo_recycle_quantity', 'orgo_tem_goo_name as tem_goo_name', 'orgo_assign_price')
->get();
} elseif ($find_vore_data->vore_order_type == 2) { //工单详情
// 查询服务项目id
$info = DB::table('work_order as wor')
->leftjoin('work_client as wocl', 'wocl.wocl_wor_id', '=', 'wor.wor_id')
->where('wor_id', $find_vore_data->vore_wor_id)
->select('wor_service_sepr_id', 'wocl_rescue_service_price')
->first();
// 根据服务项目id,查询服务名称
if ($info->wor_service_sepr_id != '0') {
$sepr_data = DB::table('service_project')
->where('sepr_id', $info->wor_service_sepr_id)
->select('sepr_name', 'sepr_order_money')
->first();
$info->ord_service_sepr_name = $sepr_data->sepr_name;
$info->sepr_order_money = $info->wocl_rescue_service_price;
unset($info->wor_service_sepr_id);
unset($info->wocl_rescue_service_price);
} else {
unset($info->wor_service_sepr_id);
}
$goods_data = DB::table('work_good')
->where('wogo_wor_id', $find_vore_data->vore_wor_id)
->where('wogo_state', '!=', 2)
->select('wogo_goo_id', 'wogo_goo_name', 'wogo_goo_goods_encode', 'wogo_goo_price', 'wogo_goo_amount', 'wogo_is_recycle', 'wogo_actual_recycle_number', 'wogo_remark', 'wogo_id', 'wogo_collection_price', 'wogo_goo_inventory', 'wogo_state', 'wogo_recycle_price', 'wogo_goo_type', 'wogo_recycle_quantity', 'wogo_tem_goo_name as tem_goo_name', 'wogo_assign_price')
->get();
} elseif ($find_vore_data->vore_order_type == 3 || $find_vore_data->vore_order_type == 5) { //采购单详情
$info = '';
$goods_data = DB::table('storage_goods')
->where('relation_number', $find_vore_data->vore_ord_number)
->leftjoin('goods', 'goo_id', '=', 'goods_id')
->select('goods_id', 'goo_cate_name', 'goo_bra_name', 'goo_goods_encode', 'goods_name as goo_name', 'goods_num', 'univalence', 'ruku_num', 'tax_rate', 'currency', 'money', 'estimate_time', 'company_unit', 'goods_type as goo_type', 'stgo_stop')
->get();
} elseif ($find_vore_data->vore_order_type == 4) {
$goods_data = DB::table('order_goods')
->where('orgo_ord_id', $find_vore_data->vore_ord_id)
->where('orgo_state', '!=', 2)
->select('orgo_goo_name', 'orgo_goo_goods_encode', 'orgo_goo_quantity', 'orgo_goo_price', 'orgo_is_recycle', 'orgo_can_assign_quantity', 'orgo_collection_price', 'orgo_goo_inventory', 'orgo_state', 'orgo_goo_type', 'orgo_recycle_price', 'orgo_recycle_quantity', 'orgo_tem_goo_name as tem_goo_name', 'orgo_assign_price')
->get();
} elseif ($find_vore_data->vore_order_type == 6) {
// 盘库单数据
$find_stoc = DB::table('stocktake as a')
->leftJoin('admin as b', 'b.adm_id', '=', 'a.stoc_adm_id')
->leftJoin('warehouse as c', 'c.ware_id', '=', 'a.stoc_ware_id')
->where('stoc_id', $find_vore_data->vore_ord_id)
->select('adm_name', 'ware_name', 'stoc_make_time', 'stoc_state', 'stoc_type', 'stoc_storage_number', 'stoc_differ_number')
->first();
// 获取盘库商品数据
$find_goods = DB::table('stocktake_goods as a')
->leftJoin('goods as b', 'a.stgo_goo_id', '=', 'b.goo_id')
->where('stgo_stoc_id', $find_vore_data->vore_ord_id)
->select('stgo_stock_number', 'stgo_lock_number', 'stgo_stocktake_number', 'goo_name', 'goo_type', 'goo_goods_encode', 'stgo_priority_stock_number', 'stgo_priority_lock_number', 'stgo_unchecked_stock_number', 'stgo_priority_stocktake_number', 'stgo_unchecked_stocktake_number')
->get();
$data['stoc_data'] = $find_stoc;
$find_goods = json_decode(json_encode($find_goods), true);
foreach ($find_goods as $key => $value) {
$find_goods[$key]['stgo_stocktake_number'] = $value['stgo_stock_number'] + $value['stgo_lock_number'] + $value['stgo_stocktake_number'];
$find_goods[$key]['stgo_priority_stocktake_number'] = $value['stgo_priority_stocktake_number'] + $value['stgo_priority_stock_number'] + $value['stgo_priority_lock_number'];
$find_goods[$key]['stgo_unchecked_stocktake_number'] = $value['stgo_unchecked_stocktake_number'] + $value['stgo_unchecked_stock_number'];
}
$data['goods_data'] = $find_goods;
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data]);
}
$data['info'] = $info;
$data['goods_data'] = $goods_data;
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data]);
}
// 备注
public function remarks(Request $request)
{
// 验证数据
$verify_data = new VerifyVoucherReceiptsController;
$error_message = $verify_data->infoValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 查找凭证列表
$find_vore_data = DB::table('voucher_receipts')
->where('vore_id', $request['vore_id'])
->select('vore_order_type', 'vore_wor_id', 'vore_wor_number', 'vore_ord_id', 'vore_ord_number')
->first();
// vore_order_type 单号类型1.订单2.工单3.采购单4.销售单
if ($find_vore_data->vore_order_type == 1) { //订单详情
$remarks_data = DB::table('order_remarks')
->where('orre_cid', $user_info->adm_cid)
->where('orre_shop_id', $user_info->adm_shop_id)
->where('orre_ord_id', $find_vore_data->vore_ord_id)
->select('orre_content', 'orre_create_adm_name', 'orre_create_adm_id', 'orre_time', 'orre_module')
->get();
} elseif ($find_vore_data->vore_order_type == 2) { //工单详情
$remarks_data = DB::table('order_remarks')
->where('orre_cid', $user_info->adm_cid)
->where('orre_shop_id', $user_info->adm_shop_id)
->where('orre_wor_id', $find_vore_data->vore_wor_id)
->select('orre_content', 'orre_create_adm_name', 'orre_create_adm_id', 'orre_time', 'orre_module')
->get();
} elseif ($find_vore_data->vore_order_type == 3 || $find_vore_data->vore_order_type == 5) { //采购单详情
$remarks_data = DB::table('note')
->where('note_adm_cid', $user_info->adm_cid)
->where('note_superior_shop_id', $shop_id)
->where('note_shop_id', $user_info->adm_shop_id)
->where('note_number', $find_vore_data->vore_ord_number)
->select('note_adm_id as orre_create_adm_id', 'note_name as orre_create_adm_name', 'note_content as orre_content', 'note_time as orre_time', 'note_type')
->get();
foreach ($remarks_data as $key => $value) {
$remarks_data[$key]->orre_module = $remarks_data[$key]->note_type;
}
} elseif ($find_vore_data->vore_order_type == 4) {
//
}
$data['remarks_data'] = $remarks_data;
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data]);
}
// 删除
public function delete(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$find_vore_data = DB::table('voucher_receipts as vore')
->leftjoin('voucher_loan as volo', 'volo.volo_vore_id', '=', 'vore.vore_id')
->where('vore_cid', $user_info->adm_cid)
->where('vore_superior_shop_id', $shop_id)
->where('vore_state', 1)
->where('vore_order_type', 6)
->get()->toArray();
if (empty($find_vore_data)) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'没有可删除的凭证数据']);
}
DB::beginTransaction();
$vore_id = array_column($find_vore_data, 'vore_id');
// 先删除凭证借贷表数据
$volo_res = DB::table('voucher_loan as b')
->leftjoin('voucher_receipts as a', 'a.vore_id', '=', 'b.volo_vore_id')
->where('vore_cid', $user_info->adm_cid)
->where('vore_superior_shop_id', $shop_id)
->whereIn('vore_id', $vore_id)
->delete();
// 再删除凭证单据表数据
$vore_res = DB::table('voucher_receipts')
->where('vore_cid', $user_info->adm_cid)
->where('vore_superior_shop_id', $shop_id)
->whereIn('vore_id', $vore_id)
->delete();
if ($volo_res && $vore_res) {
DB::commit();
Common::addLog($user_info, getRealIp($request), '凭证列表', '全部删除', '删除成功');
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'删除成功']);
} else {
DB::rollBack();
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'删除失败']);
}
}
// 业务凭证同步U8
public function sync(Request $request)
{
// 验证数据
$verify_data = new VerifyVoucherReceiptsController;
$error_message = $verify_data->syncValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
ignore_user_abort();
set_time_limit(0);
// 判断当前业务凭证是否存在
$vore_data = DB::table('voucher_receipts')
->whereIn('vore_id', $request['vore_id'])
->where('vore_state', 1)
->select('vore_id', 'vore_order_type', 'vore_wor_id', 'vore_wor_number', 'vore_ord_id', 'vore_ord_number', 'vore_type', 'vore_client_id', 'vore_channel_unit', 'vore_actual_price', 'vore_early_costing', 'vore_plus_minus', 'vore_recycle_price', 'vore_state')
->get()->toArray();
if (empty($vore_data)) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'当前业务凭证不存在']);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
if (empty($request['now_date'])) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'请选择同步U8时间']);
}
$now_date = $request['now_date'];
$vore_ord_numbers = '';
foreach ($vore_data as $key => $value) {
if ($value->vore_order_type == '2') {
$value->vore_ord_number = $value->vore_wor_number;
$vore_ord_number[] = $value->vore_wor_number;
} else {
$value->vore_ord_number = $value->vore_ord_number;
$vore_ord_number[] = $value->vore_ord_number;
}
if ($value->vore_state == '2') {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>$value->vore_ord_number . '当前凭证已同步U8']);
}
// 根据凭证id查询对应的借贷关系
$find_volo_data = DB::table('voucher_loan')
->where('volo_shop_id', $user_info->adm_shop_id)
->where('volo_vore_id', $value->vore_id)
->get()->toArray();
$find_volo_data = json_decode(json_encode($find_volo_data), true);
$vore_id = $value->vore_id;
$u8_return = YongYous::apiWorkOrder($user_info, (array)$value, $find_volo_data, $now_date); //调用u8接口
$log_data['u8_return'] = $u8_return;
if ($u8_return['code'] == 500) {
if ($u8_return['vou_data']) {
// 如果凭证添加失败,凭证号自动加1
YongYous::insertVoucher($user_info, $u8_return['vou_data'], 1);
}
$vore_ord_numbers .= $value->vore_ord_number . ', ';
} else {
$vore_edit_data['vore_state'] = 2;
$vore_edit_data['vore_update_time'] = date('Y-m-d H:i:s');
$vore_res = DB::table('voucher_receipts')
->where('vore_id', $value->vore_id)
->update($vore_edit_data);
}
}
if (!empty($acset_numbers)) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>$vore_ord_numbers . ',U8财务系统凭证上传失败2!']);
}
$log_data['time'] = date('Y-m-d H:i:s');
$log_data['user_info'] = $user_info;
$log_data['vore_ord_number'] = $vore_ord_number;
Common::write_record_log($log_data, 'pc/VoucherReceiptsController.txt', 'sync');
if ($vore_res) {
Common::addLog($user_info, getRealIp($request), '凭证列表', '同步U8', '单号(' . implode(',', $vore_ord_number) . ')同步成功');
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'U8财务系统凭证上传成功!']);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'U8财务系统凭证上传失败啦!']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountControl;
use Illuminate\Http\Request;
use App\Http\Models\Api\Common;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyReceivableAnalyzeController;
use App\Http\Models\Api\Export;
// 财务系统 -- 应收账款分析
class receivableAnalyzeController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyReceivableAnalyzeController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$search_data = $request->all();
// 会员零售统计
if ($request['recr_client_type'] == 1) {
$return_data = $this->memberStatistics($user_info);
$data_info['data'][] = $return_data; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if ($return_data) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'暂无数据']);
}
}
// 客户单位统计查询
$list_data = $this->searchclientUnitReceivable($user_info, $search_data, 1);
$list_items = $list_data->items();
if ($list_items) {
$list_items = json_decode(json_encode($list_items), true);
$chin_prec_id = array_filter(array_column($list_items, 'chin_prec_id')); //业务划区id
$adm_id = array_unique(array_column($list_items, 'chun_adm_id')); //业务员账号id
$chun_id = array_unique(array_column($list_items, 'chun_id')); //客户单位id
// today_state 当天数据是否统计:1统计2不统计
$today_state = $request->input('today_state', 2); //没有传值,默认统计状态
if ($today_state == 1) {
$start_time = null;
} else {
$start_time = date('Y-m-d') . ' 00:00:00';
}
// 截止日期
$deadline = '';//截止日期
if ($request->input('deadline')) {
$start_time = date('Y-m-d', strtotime($request->input('deadline'))). ' 23:59:59';
$deadline = $request->input('deadline');
}
// 当前余额-正值
$positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time);
// 当前余额-负值
$minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time);
// 铺货金额-正值
$distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time);
// 铺货金额-负值
$distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time);
// 30天以内(含30天) 0到30天正值
$return_time = $this->timeCalculation($today_state, 1, 30, $deadline);
$start_time = $return_time['start_time'];
$end_time = $return_time['end_time'];
$thirty_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time, $end_time);
// 30天以内(含30天) 0到30天负值
$thirty_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 30天以内(含30天)铺货金额
$thirty_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time, $end_time);
$thirty_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 31天至60天(含60天)
// $start_time = date('Y-m-d', strtotime('-60 day')).' 00:00:00';//开始时间,第60天
// $end_time = date('Y-m-d', strtotime('-31 day')).' 23:59:59';//结束时间,第31天
$return_time = $this->timeCalculation($today_state, 31, 60, $deadline);
$start_time = $return_time['start_time'];
$end_time = $return_time['end_time'];
$sixty_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time, $end_time);
// 31天至60天(含60天)
$sixty_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 31天至60天(含60天)铺货金额
$sixty_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time, $end_time);
$sixty_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 61天至90天(含90天)
// $start_time = date('Y-m-d', strtotime('-90 day')).' 00:00:00';//开始时间
// $end_time = date('Y-m-d', strtotime('-61 day')).' 23:59:59';//结束时间
$return_time = $this->timeCalculation($today_state, 61, 90, $deadline);
$start_time = $return_time['start_time'];
$end_time = $return_time['end_time'];
$ninety_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time, $end_time);
// 61天至90天(含90天)
$ninety_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 61天至90天(含90天)铺货金额
$ninety_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time, $end_time);
$ninety_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 91天至180天(含180天)
// $start_time = date('Y-m-d', strtotime('-180 day')).' 00:00:00';//开始时间
// $end_time = date('Y-m-d', strtotime('-91 day')).' 23:59:59';//结束时间
$return_time = $this->timeCalculation($today_state, 91, 180, $deadline);
$start_time = $return_time['start_time'];
$end_time = $return_time['end_time'];
$great_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time, $end_time);
// 91天至180天(含180天)
$great_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 91天至180天(含180天)铺货金额
$great_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time, $end_time);
$great_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 180以前
$greater_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time);
// 180以前
$greater_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time);
// 180以前铺货金额
$greater_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time);
$greater_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time);
foreach ($list_items as $key => $value) {
// 计算余额
$list_items[$key]['nowprice'] = $this->clientUnitCalculatePrice($positive, $minus, $value['chun_id']);
// 铺货金额
$list_items[$key]['distribution_price'] = $this->clientUnitCalculatePrice($distribution_positive, $distribution_minus, $value['chun_id']);
// 计算30天以内(含30天)余额
$list_items[$key]['thirty'] = $this->clientUnitCalculatePrice($thirty_positive, $thirty_minus, $value['chun_id']);
// 30天以内铺货金额
$thirty_distribution_price = $this->clientUnitCalculatePrice($thirty_distribution_positive, $thirty_distribution_minus, $value['chun_id']);
// 30天以内最后的金额 = 30天以内余额-30天以内铺货金额
$list_items[$key]['thirty'] = $list_items[$key]['thirty'] - $thirty_distribution_price;
// 计算比例
$list_items[$key]['thirty_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['thirty']);
// 31天至60天(含60天)
$list_items[$key]['sixty'] = $this->clientUnitCalculatePrice($sixty_positive, $sixty_minus, $value['chun_id']);
// 31天至60天铺货金额
$sixty_distribution_price = $this->clientUnitCalculatePrice($sixty_distribution_positive, $sixty_distribution_minus, $value['chun_id']);
$list_items[$key]['sixty'] = $list_items[$key]['sixty'] - $sixty_distribution_price;
// 计算比例
$list_items[$key]['sixty_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['sixty']);
// 61天至90天(含90天)
$list_items[$key]['ninety'] = $this->clientUnitCalculatePrice($ninety_positive, $ninety_minus, $value['chun_id']);
// 61天至90天铺货金额
$ninety_distribution_price = $this->clientUnitCalculatePrice($ninety_distribution_positive, $ninety_distribution_minus, $value['chun_id']);
$list_items[$key]['ninety'] = $list_items[$key]['ninety'] - $ninety_distribution_price;
// 计算比例
$list_items[$key]['ninety_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['ninety']);
// 91天至180天(含180天)
$list_items[$key]['great'] = $this->clientUnitCalculatePrice($great_positive, $great_minus, $value['chun_id']);
// 91天至180天铺货金额
$great_distribution_price = $this->clientUnitCalculatePrice($great_distribution_positive, $great_distribution_minus, $value['chun_id']);
$list_items[$key]['great'] = $list_items[$key]['great'] - $great_distribution_price;
// 计算比例
$list_items[$key]['great_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['great']);
// 180以前
$list_items[$key]['greater'] = $this->clientUnitCalculatePrice($greater_positive, $greater_minus, $value['chun_id']);
// 180以前铺货金额
$greater_distribution_price = $this->clientUnitCalculatePrice($greater_distribution_positive, $greater_distribution_minus, $value['chun_id']);
$list_items[$key]['greater'] = $list_items[$key]['greater'] - $greater_distribution_price;
// 计算比例
$list_items[$key]['greater_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['greater']);
}
// 查找业务划区数据
$find_precincts = DB::table('precincts')
->whereIn('prec_id', $chin_prec_id)
->get(['prec_id', 'prec_name']);
$data_info['find_precincts'] = $find_precincts; //业务划区
// 查找业务员
$data_info['adm_info'] = DB::table('admin')
->whereIn('adm_id', $adm_id)
->get(['adm_id', 'adm_name']);
} else {
$type_info = [];
$adm_info = [];
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if ($list_data) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'暂无数据']);
}
}
/**
* [searchclientUnitReceivable 查询应收应付的客户单位]
* @param [type] $user_info [用户信息]
* @param [type] $type [类型:1列表查询2导出]
* @return [type] [description]
*/
private function searchclientUnitReceivable($user_info, $search_data, $type)
{
$list_data = DB::table('receivable_credit as rc')
->leftJoin('channel_unit as cu', 'cu.chun_id', '=', 'rc.recr_client_id') //应收账款表
->leftJoin('channel_info as ci', 'ci.chin_chun_id', '=', 'cu.chun_id')
->where('recr_cid', $user_info->adm_cid)
->where('recr_shop_id', $user_info->adm_shop_id)
->where('recr_client_type', 2) //客户类型:1会员零售2来往单位
->where('recr_belongs_id', '=', 0)
->where('recr_state', '!=', 2) //状态:1未确认2已确认3已收款4已付款
->where(function ($query) use ($search_data) { //单位名称
if (!empty($search_data['chun_name'])) {
$query->where('chun_unit_name', 'like', '%' . $search_data['chun_name'] . '%');
}
})
->where(function ($query) use ($search_data) { //客户电话
if (!empty($search_data['chin_zoning'])) {
$query->where('chin_zoning', 'like', '%' . $search_data['chin_zoning'] . '%');
}
})
->where(function ($query) use ($search_data) { //业务员
if (!empty($search_data['chun_search_letter'])) {
$query->where('chun_search_letter', $search_data['chun_search_letter']);
}
})
->where(function ($query) use ($search_data) { //业务划区id
if (!empty($search_data['chin_prec_id'])) {
$query->where('chin_prec_id', $search_data['chin_prec_id']);
}
})
->where(function ($query) use ($search_data) { //客户单位id
if (!empty($search_data['recr_client_id'])) {
$query->where('recr_client_id', $search_data['recr_client_id']);
}
})
->where(function ($query) use ($search_data) { //业务员id
if (!empty($search_data['chun_adm_id'])) {
$query->where('chun_adm_id', $search_data['chun_adm_id']);
}
})
->where(function ($query) use ($search_data) { //结算方式1账期2现结
if (!empty($search_data['chun_payment_way'])) {
$query->where('chun_payment_way', $search_data['chun_payment_way']);
}
})
->select(DB::raw('chun_id, chun_unit_name, chun_search_letter, chun_payment_way, chin_prec_id, chun_adm_id'))
->groupBy('chun_id');
if ($type == 1) {
$list_data = $list_data->paginate($this->show_count);
} else {
$list_data = $list_data->get()->toArray();
}
return $list_data;
}
/**
* [timeCalculation 时间计算]
* @param [type] $today_state [当天数据是否统计:1统计2不统计]
* @param [type] $start_days [开始天数]
* @param [type] $end_days [结束天数]
* @return [type] [description]
*/
private function timeCalculation($today_state, $start_days, $end_days, $deadline='')
{
if ($today_state == 1) {
// 统计当天数据
// $start_time = date('Y-m-d H:i:s', strtotime('-30 day'));//开始时间
// $end_time = date('Y-m-d H:i:s', strtotime('-0 day'));//结束时间
$start_days = $start_days - 1;
if ($deadline) {
// 前端选择了截止时间
$start_time = date('Y-m-d H:i:s', strtotime('-' . $end_days . ' day', strtotime($deadline)) + 1); //开始时间
$end_time = date('Y-m-d H:i:s', strtotime('-' . $start_days . ' day', strtotime($deadline))); //结束时间
} else {
$start_time = date('Y-m-d H:i:s', strtotime('-' . $end_days . ' day') + 1); //开始时间,加1秒
$end_time = date('Y-m-d H:i:s', strtotime('-' . $start_days . ' day')); //结束时间
}
} else {
// 30天以内(含30天) 0到30天正值,不统计当天数据
if ($deadline) {
// dump($end_days);
// dump($start_days);
$start_days = $start_days - 1;
$end_days = $end_days - 1;
// 前端选择了截止时间
$start_time = date('Y-m-d', strtotime('-' . $end_days . ' day', strtotime($deadline))) . ' 00:00:00'; //开始时间
$end_time = date('Y-m-d', strtotime('-' . $start_days . ' day', strtotime($deadline))) . ' 23:59:59'; //结束时间
} else {
// 前端没有选择截止时间
$start_time = date('Y-m-d', strtotime('-' . $end_days . ' day')) . ' 00:00:00'; //开始时间
$end_time = date('Y-m-d', strtotime('-' . $start_days . ' day')) . ' 23:59:59'; //结束时间
}
}
$data['end_time'] = $end_time;
$data['start_time'] = $start_time;
return $data;
}
/**
* [clientUnitTimeBucketPrice 统计客户单位时间段应收应付金额]
* @param [type] $user_info [用户信息]
* @param [type] $recr_plus_minus [金额正负:1正值2负值]
* @param [type] $chun_id [客户单位id,数组]
* @param [type] $start_time [开始时间]
* @param [type] $end_time [结束时间]
* @return [type] [description]
*/
private function clientUnitTimeBucketPrice($user_info, $recr_plus_minus, $chun_id, $start_time = null, $end_time = null)
{
$time_bucket_price = collect(DB::table('receivable_credit')
->where('recr_cid', $user_info->adm_cid)
->where('recr_shop_id', $user_info->adm_shop_id)
->where('recr_plus_minus', $recr_plus_minus) //金额正负:1正值2负值
->where('recr_client_type', 2) //客户类型:1会员零售2来往单位
->where('recr_belongs_id', '=', 0)
->where('recr_state', '!=', 2) //状态:1未确认2已确认3已收款4已付款
->whereIn('recr_client_id', $chun_id)
->where(function ($query) use ($start_time, $end_time) {
if (!empty($start_time) && !empty($end_time)) {
$query->whereBetween('recr_order_time', [$start_time, $end_time]);
} elseif (!empty($start_time)) {
// 180天以上,截止时间
$query->where('recr_order_time', '<', $start_time);
}
})
->select(DB::Raw('sum(recr_settle_price) as recr_settle_price,sum(recr_yet_receipt) as recr_yet_receipt,sum(recr_zero_price) as recr_zero_price,recr_client_id'))
->groupBy('recr_client_id')
->get())->keyBy('recr_client_id')->toArray();
return $time_bucket_price;
}
/**
* [clientUnitTimeBucketDistributionPrice 统计客户单位时间段应收应付的铺货金额]
* @param [type] $user_info [用户信息]
* @param [type] $recr_plus_minus [金额正负:1正值2负值]
* @param [type] $chun_id [客户单位id,数组]
* @param [type] $start_time [开始时间]
* @param [type] $end_time [结束时间]
* @return [type] [description]
*/
private function clientUnitTimeBucketDistributionPrice(
$user_info,
$recr_plus_minus,
$chun_id,
$start_time = null,
$end_time = null
) {
$time_bucket_price = collect(DB::table('receivable_credit as rc')
->leftjoin('order_client as oc', 'oc.orcl_ord_id', '=', 'rc.recr_original_id')
->where('recr_cid', $user_info->adm_cid)
->where('recr_shop_id', $user_info->adm_shop_id)
->where('recr_plus_minus', $recr_plus_minus) //金额正负:1正值2负值
->where('recr_client_type', 2) //客户类型:1会员零售2来往单位
->where('recr_belongs_id', '=', 0)
->where('recr_state', '!=', 2) //状态:1未确认2已确认3已收款4已付款
->where('recr_type', 3) //类型:1销售订单2预收款3订单账单
->where('recr_account_type', '!=', 5) //5订单账单
->where('orcl_chin_type', 1) //订单是否铺货:1是2否
->whereIn('recr_client_id', $chun_id)
->where(function ($query) use ($start_time, $end_time) {
if (!empty($start_time) && !empty($end_time)) {
$query->whereBetween('recr_order_time', [$start_time, $end_time]);
} elseif (!empty($start_time)) {
// 180天以上
$query->where('recr_order_time', '<', $start_time);
}
})
->select(DB::Raw('sum(recr_settle_price) as recr_settle_price,sum(recr_yet_receipt) as recr_yet_receipt,sum(recr_zero_price) as recr_zero_price,recr_client_id'))
->groupBy('recr_client_id')
->get())->keyBy('recr_client_id')->toArray();
return $time_bucket_price;
}
/**
* [memberStatistics 会员零售统计]
* @param [type] $user_info [用户信息]
* @return [type] [description]
*/
private function memberStatistics($user_info)
{
// 应收应付的正数金额
$positive_price = $this->memberTimeBucketPrice($user_info, 1);
// 应收应付的负数金额
$minus_price = $this->memberTimeBucketPrice($user_info, 2);
// 计算当前余额
$nowprice = $this->memberCalculatePrice((array)$positive_price, (array)$minus_price);
// 30天以内(含30天) 0到30天正值
$start_time = date('Y-m-d', strtotime('-30 day')) . ' 00:00:00'; //开始时间
$end_time = date('Y-m-d', strtotime('-1 day')) . ' 23:59:59'; //结束时间
$thirty_positive = $this->memberTimeBucketPrice($user_info, 1, $start_time, $end_time);
// 30天以内(含30天) 0到30天负值
$thirty_minus = $this->memberTimeBucketPrice($user_info, 2, $start_time, $end_time);
// 计算余额
$thirty = $this->memberCalculatePrice((array)$thirty_positive, (array)$thirty_minus);
// 计算比例
$thirty_ratio = $this->computeRatio($nowprice, $thirty);
// 31天至60天(含60天)
$start_time = date('Y-m-d', strtotime('-60 day')) . ' 00:00:00'; //开始时间,第60天
$end_time = date('Y-m-d', strtotime('-31 day')) . ' 23:59:59'; //结束时间,第31天
$sixty_positive = $this->memberTimeBucketPrice($user_info, 1, $start_time, $end_time);
// 31天至60天(含60天) 0到30天负值
$sixty_minus = $this->memberTimeBucketPrice($user_info, 2, $start_time, $end_time);
// 计算余额
$sixty = $this->memberCalculatePrice((array)$sixty_positive, (array)$sixty_minus);
// 计算比例
$sixty_ratio = $this->computeRatio($nowprice, $sixty);
// 61天至90天(含90天)
$start_time = date('Y-m-d', strtotime('-90 day')) . ' 00:00:00'; //开始时间
$end_time = date('Y-m-d', strtotime('-61 day')) . ' 23:59:59'; //结束时间
$ninety_positive = $this->memberTimeBucketPrice($user_info, 1, $start_time, $end_time);
// 61天至90天(含90天)
$ninety_minus = $this->memberTimeBucketPrice($user_info, 2, $start_time, $end_time);
// 计算余额
$ninety = $this->memberCalculatePrice((array)$ninety_positive, (array)$ninety_minus);
// 计算比例
$ninety_ratio = $this->computeRatio($nowprice, $ninety);
// 91天至180天(含180天)
$start_time = date('Y-m-d', strtotime('-180 day')) . ' 00:00:00'; //开始时间
$end_time = date('Y-m-d', strtotime('-91 day')) . ' 23:59:59'; //结束时间
$great_positive = $this->memberTimeBucketPrice($user_info, 1, $start_time, $end_time);
// 91天至180天(含180天)
$great_minus = $this->memberTimeBucketPrice($user_info, 2, $start_time, $end_time);
// 计算余额
$great = $this->memberCalculatePrice((array)$great_positive, (array)$great_minus);
// 计算比例
$great_ratio = $this->computeRatio($nowprice, $great);
// 180天以上
$start_time = date('Y-m-d', strtotime('-180 day')) . ' 00:00:00'; //开始时间
$greater_positive = $this->memberTimeBucketPrice($user_info, 1, $start_time);
// 180天以上
$greater_minus = $this->memberTimeBucketPrice($user_info, 2, $start_time);
// 计算余额
$greater = $this->memberCalculatePrice((array)$greater_positive, (array)$greater_minus);
// 计算比例
$greater_ratio = $this->computeRatio($nowprice, $greater);
$return_data['nowprice'] = $nowprice; //当前余额
$return_data['thirty'] = $thirty; //30天以内余额(含30天)
$return_data['thirty_ratio'] = $thirty_ratio; //三十天以内比例(含30天)
$return_data['sixty'] = $sixty; //31天到60天余额(含60天)
$return_data['sixty_ratio'] = $sixty_ratio; //31天到60天比例(含60天)
$return_data['ninety'] = $ninety; //61天到90天余额(含90天)
$return_data['ninety_ratio'] = $ninety_ratio; //61天到90天比例(含90天)
$return_data['great'] = $great; //91天到180天余额(含180天)
$return_data['great_ratio'] = $great_ratio; //91天到180天比例(含180天)
$return_data['greater'] = $greater; //180天以上余额
$return_data['greater_ratio'] = $greater_ratio; //180天以上比例
return $return_data;
}
/**
* [memberTimeBucketPrice 统计会员零售时间段应收应付金额]
* @param [type] $user_info [用户信息]
* @param [type] $recr_plus_minus [金额正负:1正值2负值]
* @param [type] $start_time [开始时间]
* @param [type] $end_time [结束时间]
* @return [type] [description]
*/
private function memberTimeBucketPrice($user_info, $recr_plus_minus, $start_time = null, $end_time = null)
{
$time_bucket_price = DB::table('receivable_credit as rc')
->where('recr_cid', $user_info->adm_cid)
->where('recr_shop_id', $user_info->adm_shop_id)
->where('recr_plus_minus', $recr_plus_minus) //金额正负:1正值2负值
->where('recr_client_type', 1) //客户类型:1会员零售2来往单位
->where('recr_belongs_id', '=', 0)
->where('recr_state', '!=', 2) //状态:1未确认2已确认3已收款4已付款
->where(function ($query) use ($start_time, $end_time) {
if (!empty($start_time) && !empty($end_time)) {
$query->whereBetween('recr_order_time', [$start_time, $end_time]);
} elseif (!empty($start_time)) {
// 180天以上
$query->where('recr_order_time', '<', $start_time);
}
})
->select(DB::raw('sum(recr_settle_price) as recr_settle_price,sum(recr_actual_price) as recr_actual_price,sum(recr_yet_receipt) as recr_yet_receipt,sum(recr_zero_price) as recr_zero_price'))
->first();
return $time_bucket_price;
}
/**
* [computeRatio 计算金额比例]
* @param [type] $denominator [分母]
* @param [type] $numerator [分子]
* @return [type] [description]
*/
private function computeRatio($denominator, $numerator)
{
if (empty($denominator) && empty($numerator)) {
$ratio = 0;
} else {
if ($denominator == 0) {
$ratio = 0;
} else {
$ratio = round($numerator / $denominator, 2) * 100;
}
}
return $ratio;
}
/**
* [memberCalculatePrice 会员零售计算金额]
* @param [type] $positive_price [正数金额]
* @param [type] $minus_price [负数金额]
* @return [type] [description]
*/
private function memberCalculatePrice($positive_price, $minus_price)
{
// recr_settle_price 结算金额
$positive_settle_price = isset($positive_price['recr_settle_price']) ? $positive_price['recr_settle_price'] : 0;
$minus_settle_price = isset($minus_price['recr_settle_price']) ? $minus_price['recr_settle_price'] : 0;
$settle_price = $positive_settle_price - $minus_settle_price; //当前的结算金额
// recr_yet_receipt 已收金额
$positive_yet_receipt = isset($positive_price['recr_yet_receipt']) ? $positive_price['recr_yet_receipt'] : 0;
$minus_yet_receipt = isset($minus_price['recr_yet_receipt']) ? $minus_price['recr_yet_receipt'] : 0;
$yet_receipt = $positive_yet_receipt - $minus_yet_receipt;
// recr_zero_price 抹零金额
$positive_zero_price = isset($positive_price['recr_zero_price']) ? $positive_price['recr_zero_price'] : 0;
$minus_zero_price = isset($minus_price['recr_zero_price']) ? $minus_price['recr_zero_price'] : 0;
$zero_price = $positive_zero_price - $minus_zero_price;
// 当前的欠收金额 = 结算金额 - 已收金额 - 抹零金额
$bad_crop_price = $settle_price - $yet_receipt - $zero_price;
return $bad_crop_price;
}
/**
* [clientUnitCalculatePrice 客户单位计算金额]
* @param [type] $positive_price [正数金额]
* @param [type] $minus_price [负数金额]
* @return [type] [description]
*/
private function clientUnitCalculatePrice($positive_price, $minus_price, $chun_id)
{
// recr_settle_price 结算金额
$positive_settle_price = isset($positive_price[$chun_id]->recr_settle_price) ? $positive_price[$chun_id]->recr_settle_price : 0;
$minus_settle_price = isset($minus_price[$chun_id]->recr_settle_price) ? $minus_price[$chun_id]->recr_settle_price : 0;
$settle_price = $positive_settle_price - $minus_settle_price; //当前的结算金额
// recr_yet_receipt 已收金额
$positive_yet_receipt = isset($positive_price[$chun_id]->recr_yet_receipt) ? $positive_price[$chun_id]->recr_yet_receipt : 0;
$minus_yet_receipt = isset($minus_price[$chun_id]->recr_yet_receipt) ? $minus_price[$chun_id]->recr_yet_receipt : 0;
$yet_receipt = $positive_yet_receipt - $minus_yet_receipt;
// recr_zero_price 抹零金额
$positive_zero_price = isset($positive_price[$chun_id]->recr_zero_price) ? $positive_price[$chun_id]->recr_zero_price : 0;
$minus_zero_price = isset($minus_price[$chun_id]->recr_zero_price) ? $minus_price[$chun_id]->recr_zero_price : 0;
$zero_price = $positive_zero_price - $minus_zero_price;
// 当前的欠收金额 = 结算金额 - 已收金额 - 抹零金额
$bad_crop_price = $settle_price - $yet_receipt - $zero_price;
return $bad_crop_price;
}
// 导出
public function export(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$search_data = $request->all();
// 会员零售统计
if ($request['recr_client_type'] == 1) {
$list_data = $this->memberStatistics($user_info);
if (empty($list_data)) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'没有符合搜索条件的数据!']);
}
$list_data['nowprice'] = $list_data['nowprice'] / 100;
$list_data['thirty'] = $list_data['thirty'] / 100;
$list_data['thirty_ratio'] = $list_data['thirty_ratio'] . '%';
$list_data['sixty'] = $list_data['sixty'] / 100;
$list_data['sixty_ratio'] = $list_data['sixty_ratio'] . '%';
$list_data['ninety'] = $list_data['ninety'] / 100;
$list_data['ninety_ratio'] = $list_data['ninety_ratio'] . '%';
$list_data['great'] = $list_data['great'] / 100;
$list_data['great_ratio'] = $list_data['great_ratio'] . '%';
$list_data['greater'] = $list_data['greater'] / 100;
$list_data['greater_ratio'] = $list_data['greater_ratio'] . '%';
$list_data = array_merge(['name' => '会员零售'], $list_data);
$list_items[] = $list_data;
$pathName = storage_path() . "/app/public/excel"; //获取上传excel路径
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName, 0775, true);
chmod($pathName, 0775);
}
$streamFileRand = '应收账款分析' . time() . rand(1000, 9999) . '.xls';
// 产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
$streamFilename = $pathName . '/' . $streamFileRand;
$where['action_name'] = '应收账款分析';
$where['field_name'] = ['名称', '当前余额', '30天以内余额(含30天)', '30天以内比例(含30天)', '31天至60天余额(含60天)', '31天至60天比例(含60天)', '61天至90天余额(含90天)', '61天至90天比例(含90天)', '91天至180天余额(含180天)', '91天至180天比例(含180天)', '180天以上余额', '180天以上比例'];
// 调用导出的公共方法
export::publicExport(
$streamFilename, //路径
$where, //sheet名及其每一行的标题
$list_items //导出数据
);
// 判断文件是否存在 存在则成功 不存在则失败
if (file_exists($pathName)) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'storage/excel/' . $streamFileRand]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'导出失败']);
}
}
// 客户单位类型统计
$list_data = $this->searchclientUnitReceivable($user_info, $search_data, 2);
$list_items = json_decode(json_encode($list_data), true);
if (empty($list_items)) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'没有符合搜索条件的数据!']);
}
$pathName = storage_path() . "/app/public/excel"; //获取上传excel路径
// 创建文件夹
if (!file_exists($pathName)) {
mkdir($pathName, 0775, true);
chmod($pathName, 0775);
}
$chun_id = array_unique(array_column($list_items, 'chun_id')); //客户单位id
// today_state 当天数据是否统计:1统计2不统计
$today_state = $request->input('today_state', 2); //没有传值,默认统计状态
if ($today_state == 1) {
$start_time = null;
} else {
$start_time = date('Y-m-d') . ' 00:00:00';
}
// 截止日期
$deadline = '';//截止日期
if ($request->input('deadline')) {
$start_time = date('Y-m-d', strtotime($request->input('deadline'))). ' 23:59:59';
$deadline = $request->input('deadline');
}
// 正值
$positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time);
// 负值
$minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time);
// 铺货金额-正值
$distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time);
// 铺货金额-负值
$distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time);
// 30天以内(含30天) 0到30天正值
// $start_time = date('Y-m-d', strtotime('-30 day')).' 00:00:00';//开始时间
// $end_time = date('Y-m-d', strtotime('-1 day')).' 23:59:59';//结束时间
$return_time = $this->timeCalculation($today_state, 1, 30, $deadline);
$start_time = $return_time['start_time'];
$end_time = $return_time['end_time'];
$thirty_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time, $end_time);
// 30天以内(含30天) 0到30天负值
$thirty_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 30天以内(含30天)铺货金额
$thirty_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time, $end_time);
$thirty_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 31天至60天(含60天)
// $start_time = date('Y-m-d', strtotime('-60 day')).' 00:00:00';//开始时间,第60天
// $end_time = date('Y-m-d', strtotime('-31 day')).' 23:59:59';//结束时间,第31天
$return_time = $this->timeCalculation($today_state, 31, 60, $deadline);
$start_time = $return_time['start_time'];
$end_time = $return_time['end_time'];
$sixty_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time, $end_time);
// 31天至60天(含60天)
$sixty_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 31天至60天(含60天)铺货金额
$sixty_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time, $end_time);
$sixty_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 61天至90天(含90天)
// $start_time = date('Y-m-d', strtotime('-90 day')).' 00:00:00';//开始时间
// $end_time = date('Y-m-d', strtotime('-61 day')).' 23:59:59';//结束时间
$return_time = $this->timeCalculation($today_state, 61, 90, $deadline);
$start_time = $return_time['start_time'];
$end_time = $return_time['end_time'];
$ninety_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time, $end_time);
// 61天至90天(含90天)
$ninety_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 61天至90天(含90天)铺货金额
$ninety_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time, $end_time);
$ninety_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 91天至180天(含180天)
// $start_time = date('Y-m-d', strtotime('-180 day')).' 00:00:00';//开始时间
// $end_time = date('Y-m-d', strtotime('-91 day')).' 23:59:59';//结束时间
$return_time = $this->timeCalculation($today_state, 91, 180, $deadline);
$start_time = $return_time['start_time'];
$end_time = $return_time['end_time'];
$great_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time, $end_time);
// 91天至180天(含180天)
$great_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 91天至180天(含180天)铺货金额
$great_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time, $end_time);
$great_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time, $end_time);
// 180以前
// $start_time = date('Y-m-d', strtotime('-180 day')).' 00:00:00';//开始时间
$greater_positive = $this->clientUnitTimeBucketPrice($user_info, 1, $chun_id, $start_time);
// 180以前
$greater_minus = $this->clientUnitTimeBucketPrice($user_info, 2, $chun_id, $start_time);
// 180以前铺货金额
$greater_distribution_positive = $this->clientUnitTimeBucketDistributionPrice($user_info, 1, $chun_id, $start_time);
$greater_distribution_minus = $this->clientUnitTimeBucketDistributionPrice($user_info, 2, $chun_id, $start_time);
$chin_prec_id = array_filter(array_column($list_items, 'chin_prec_id')); //业务划区id
$chun_adm_id = array_unique(array_column($list_items, 'chun_adm_id')); //业务员账号id
// 查找业务划区
$prec_data = DB::table('precincts')
->whereIn('prec_id', $chin_prec_id)
->pluck('prec_name', 'prec_id')
->toArray();
// 查询业务员
$adm_data = DB::table('admin')
->whereIn('adm_id', $chun_adm_id)
->pluck('adm_name', 'adm_id')
->toArray();
foreach ($list_items as $key => $value) {
// 计算余额
$list_items[$key]['nowprice'] = $this->clientUnitCalculatePrice($positive, $minus, $value['chun_id']);
// 铺货金额
$list_items[$key]['distribution_price'] = $this->clientUnitCalculatePrice($distribution_positive, $distribution_minus, $value['chun_id']);
// 计算30天以内(含30天)余额
$list_items[$key]['thirty'] = $this->clientUnitCalculatePrice($thirty_positive, $thirty_minus, $value['chun_id']);
// 30天以内铺货金额
$thirty_distribution_price = $this->clientUnitCalculatePrice($thirty_distribution_positive, $thirty_distribution_minus, $value['chun_id']);
// 30天以内最后的金额 = 30天以内余额-30天以内铺货金额
$list_items[$key]['thirty'] = $list_items[$key]['thirty'] - $thirty_distribution_price;
// 计算比例
$list_items[$key]['thirty_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['thirty']);
// 31天至60天(含60天)
$list_items[$key]['sixty'] = $this->clientUnitCalculatePrice($sixty_positive, $sixty_minus, $value['chun_id']);
// 31天至60天铺货金额
$sixty_distribution_price = $this->clientUnitCalculatePrice($sixty_distribution_positive, $sixty_distribution_minus, $value['chun_id']);
$list_items[$key]['sixty'] = $list_items[$key]['sixty'] - $sixty_distribution_price;
// 计算比例
$list_items[$key]['sixty_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['sixty']);
// 61天至90天(含90天)
$list_items[$key]['ninety'] = $this->clientUnitCalculatePrice($ninety_positive, $ninety_minus, $value['chun_id']);
// 61天至90天铺货金额
$ninety_distribution_price = $this->clientUnitCalculatePrice($ninety_distribution_positive, $ninety_distribution_minus, $value['chun_id']);
$list_items[$key]['ninety'] = $list_items[$key]['ninety'] - $ninety_distribution_price;
// 计算比例
$list_items[$key]['ninety_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['ninety']);
// 91天至180天(含180天)
$list_items[$key]['great'] = $this->clientUnitCalculatePrice($great_positive, $great_minus, $value['chun_id']);
// 91天至180天铺货金额
$great_distribution_price = $this->clientUnitCalculatePrice($great_distribution_positive, $great_distribution_minus, $value['chun_id']);
$list_items[$key]['great'] = $list_items[$key]['great'] - $great_distribution_price;
// 计算比例
$list_items[$key]['great_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['great']);
// 180以前
$list_items[$key]['greater'] = $this->clientUnitCalculatePrice($greater_positive, $greater_minus, $value['chun_id']);
// 180以前铺货金额
$greater_distribution_price = $this->clientUnitCalculatePrice($greater_distribution_positive, $greater_distribution_minus, $value['chun_id']);
$list_items[$key]['greater'] = $list_items[$key]['greater'] - $greater_distribution_price;
// 计算比例
$list_items[$key]['greater_ratio'] = $this->computeRatio($list_items[$key]['nowprice'], $list_items[$key]['greater']);
if ($value['chin_prec_id']) {
$list_items[$key]['chin_prec_id'] = $prec_data[$value['chin_prec_id']]; //业务划区id
} else {
$list_items[$key]['chin_prec_id'] = ''; //业务划区id
}
if ($value['chun_adm_id']) {
if (isset($adm_data[$value['chun_adm_id']])) {
$list_items[$key]['chun_adm_id'] = $adm_data[$value['chun_adm_id']]; //业务员
} else {
$list_items[$key]['chun_adm_id'] = '';
}
} else {
$list_items[$key]['chun_adm_id'] = ''; //业务员
}
// chun_payment_way 结算方式1账期2现结
if ($value['chun_payment_way'] == 1) {
$list_items[$key]['chun_payment_way'] = '账期';
} else {
$list_items[$key]['chun_payment_way'] = '现结';
}
$list_items[$key]['nowprice'] = $list_items[$key]['nowprice'] / 100; //当前余额
$list_items[$key]['distribution_price'] = $list_items[$key]['distribution_price'] / 100; //当前余额
$list_items[$key]['thirty'] = $list_items[$key]['thirty'] / 100; //30天以内余额
$list_items[$key]['thirty_ratio'] = $list_items[$key]['thirty_ratio'] . '%'; //30天以内比例
$list_items[$key]['sixty'] = $list_items[$key]['sixty'] / 100; //30天至60天余额
$list_items[$key]['sixty_ratio'] = $list_items[$key]['sixty_ratio'] . '%'; //30天至60天比例
$list_items[$key]['ninety'] = $list_items[$key]['ninety'] / 100; //60天-90天余额
$list_items[$key]['ninety_ratio'] = $list_items[$key]['ninety_ratio'] . '%'; //60天-90天比例
$list_items[$key]['great'] = $list_items[$key]['great'] / 100; //90天-180天余额
$list_items[$key]['great_ratio'] = $list_items[$key]['great_ratio'] . '%'; //90天-180天比例
$list_items[$key]['greater'] = $list_items[$key]['greater'] / 100; //180天以上
$list_items[$key]['greater_ratio'] = $list_items[$key]['greater_ratio'] . '%'; //180天比例
unset($list_items[$key]['chun_id']);
}
$streamFileRand = '应收账款分析' . time() . rand(1000, 9999) . '.xls';
// 产生一个随机文件名(因为你base64上来肯定没有文件名,这里你可以自己设置一个也行)
$streamFilename = $pathName . '/' . $streamFileRand;
$where['action_name'] = '应收账款分析';
$where['field_name'] = ['客户单位名称', '检索字母', '结算方式', '业务划区', '业务员', '当前余额', '铺货金额', '30天以内余额(含30天)', '30天以内比例(含30天)', '31天至60天余额(含60天)', '31天至60天比例(含60天)', '61天至90天余额(含90天)', '61天至90天比例(含90天)', '91天至180天余额(含180天)', '91天至180天比例(含180天)', '180天以上余额', '180天以上比例'];
// 调用导出的公共方法
export::publicExport(
$streamFilename, //路径
$where, //sheet名及其每一行的标题
$list_items //导出数据
);
// 判断文件是否存在 存在则成功 不存在则失败
if (file_exists($pathName)) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'storage/excel/' . $streamFileRand]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'导出失败']);
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
namespace App\Http\Controllers\Api\AccountControl;
use App\Http\Models\Api\ReceivablePay;
use App\Services\Business\WashOrderService;
use App\Services\Business\WashWorkService;
use App\Services\CommonService;
use App\Services\LoginUserService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountControl\VerifyReceivableBillController;
use App\Http\Models\Api\Export;
use App\Http\Models\Api\Common;
use App\Http\Models\Api\ReceivableBill;
use App\Http\Models\Api\AccountingSettlement;
use App\Http\Models\Api\AccountTitle;
use App\Http\Models\Api\AccountSubject;
use App\Services\ReceivablePay\ReceivablePayService;
// 财务系统 -- 订单应收应付
class receivablePayController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
/*
* @name 修改应收应付状态
* @param string ju_ordernum 订单单号
* @retrun array
* @author Ma 2023/7/24 11:42
*
*/
public function edit(Request $request)
{
$request = $request->all();
$data_validator = ReceivablePayService::editValidator($request);
if($data_validator['code'] != 200){
//return response()->json($data_validator);exit;
}
if($request['type'] == 1){
return ReceivablePayService::info($request);
}else{
return ReceivablePayService::edit($request);
}
}
/*
* @name 添加订单应收应付
* @param string ju_ordernum 订单单号
* @retrun array
* @author Ma 2023/7/24 11:42
*
*/
public function add(Request $request)
{
$request = $request->all();
$data_validator = ReceivablePayService::addValidator(json_decode(json_encode($request),true));
if($data_validator['code'] != 200){
return response()->json($data_validator);exit;
}
/* $params = [
'user_info'=>$user_info,
'ord_type'=>$request['ord_type'],
'ord_client_id'=> isset($request['ord_client_id']) ? $request['ord_client_id'] : 0,
'ord_order_price'=>$ord_edit_data['ord_order_price']
];*/
//添加订单应收应付
return ReceivablePayService::add($request);
}
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyReceivableBillController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$search_data = $request->all();
return ReceivablePayService::index($search_data);
}
/*
* @name 详情
* @param id 应收应付id
* @retrun array
* @author Ma 2023/7/24 18:20
*
*/
public function info(Request $request){
// 验证参数
/*$error_message = $this->dataService->mainValidator->infoValidator($request->all());
if (!empty($error_message)) {
return $this->error('请求参数错误!', ErrorInc::INVALID_PARAM, $error_message);
}*/
$order_data = [];
$word_data = [];
// 获取用户信息
$user_info = LoginUserService::getUser();
$order_data = WashOrderService::info($user_info, $request->all());//订单信息
if($order_data['code'] == 200){
$order_data = $order_data['data'];
}
$all_work_orders = DB::table('work_order')->where('wor_order_id', $request['ord_id'])->get()->toArray();
foreach ($all_work_orders as $work_key => $work_value){
$word_info = WashWorkService::info($user_info, ['wor_id'=>$work_value->wor_id,'type'=>1]);//工单信息
$word_data[] = $word_info['data'];
}
$data['order_info'] = $order_data;//订单信息
$data['work_info'] = $word_data;//工单信息
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data]);
}
/*
* @name 导出
* @param string ju_ordernum 订单单号
* @retrun array
* @author Ma 2023/8/9 16:00
*
*/
public function export(Request $request){
// 验证数据
$verify_data = new VerifyReceivableBillController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$search_data = $request->all();
return ReceivablePayService::export($search_data);
}
}
<?php
namespace App\Http\Controllers\Api\AccountManage;
use App\Services\CommonService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountManage\VerifyBillContrastController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
use App\Http\Models\Api\ReceivableBill;
use App\Http\Models\Api\AccountingSettlement;
use App\Http\Models\Api\YongYou;
use App\Services\ReceivablePay\ReceivablePayService;
// 财务系统 -- 速电账单
class BillContrastController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
$search_data = $request->all();
$list_data = DB::table('sd_order_bill')
->where('sdob_cid', $user_info->adm_cid)
->where('sdob_superior_shop_id', $shop_id)
->where(function ($query) use ($search_data) {
if (!empty($search_data['sd_bill_bumber'])) {
$query->where('sdob_sd_bill_bumber', 'like', '%' . $search_data['sd_bill_bumber'] . '%');
}
}) //账单状态
->where(function ($query) use ($search_data) {
if (is_numeric($search_data['sdob_state'])) {
$query->where('sdob_state', $search_data['sdob_state']);
}
}) //账单状态
->where(function ($query) use ($search_data) {
//如果选择开始时间并且选择结束时间
if (!empty($search_data['start_time']) && !empty($search_data['end_time'])) {
$query->whereBetween('sdob_create_time', [$search_data['start_time'], $search_data['end_time'] . ' 23:59:59']);
} else {
// 如果选择开始时间
if (!empty($search_data['start_time'])) {
$query->where('sdob_create_time', '>=', $search_data['start_time']);
} else {
// 如果选择结束时间
if (!empty($search_data['end_time'])) {
$query->where('sdob_create_time', '<=', $search_data['end_time'] . ' 23:59:59');
}
}
}
}) //创建时间
->select('sdob_id', 'sdob_start_time', 'sdob_end_time', 'sdob_bill_price', 'sdob_create_time', 'sdob_state', 'sdob_orbi_number', 'sdob_sd_bill_price', 'sdob_sd_bill_bumber', 'sdob_shop_name', 'sdob_stl_ticket')
->orderBy('sdob_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
$status_name = self::getStatsName(true);
foreach ($list_items as $key => $value) {
$buttonData = [];
if($value->sdob_state == 0){//未确认
$buttonData[] = 'audit';
}
$buttonData[] = 'look';
$button = CommonService::getListButton($buttonData,$list_button);
$list_items[$key]->button_one = $button['button_one']??[];
$list_items[$key]->button_two = $button['button_two']??[];
$list_items[$key]->button_three = $button['button_three']??[];
$list_items[$key]->sdob_state_name = $status_name[$value->sdob_state];
$list_items[$key]->sdob_nvoicingi_amount = $value->sdob_sd_bill_price - $value->sdob_stl_ticket;//开票金额
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['status'] = self::getStatsName();
if ($list_data) {
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'暂无数据']);
}
}
/*
* @name 状态值
* @param string ju_ordernum
* @retrun array
* @author Ma 2023/8/3 19:39
*
*/
public function getStatsName($type=false)
{
$status_names = [['type'=>'0','value'=>'未确认'],['type'=>'1','value'=>'结算中'],['type'=>'3','value'=>'已结款'],['type'=>'2','value'=>'已撤销']];
if($type){
$status_names = array_column($status_names,'value','type');
}
return $status_names;
}
// 确认
public function affirm(Request $request)
{
if (empty($request['sdob_id']) || empty($request['type']) || !in_array($request['type'], [1, 2])) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误']);
}
if ($request['type'] == 1) {
$sd_bill = DB::table('sd_order_bill')
->where('sdob_id', $request['sdob_id'])
->first(['sdob_sd_bill_bumber', 'sdob_start_time', 'sdob_end_time', 'sdob_bill_price', 'sdob_orbi_id', 'sdob_shop_name']);
$data['sd_order'] = DB::table('sd_order_bill_details')
->where('sobd_sdob_id', $request['sdob_id'])
->get(['sobd_order_number', 'sobd_actual_price', 'sobd_relative_price', 'sobd_ord_id', 'sobd_details_price', 'sobd_car_owner_name']);
foreach ($data['sd_order'] as $key => $value) {
$data['sd_order'][$key]->sobd_details_price = json_decode($value->sobd_details_price);
}
$data['mk_order'] = DB::table('order')
->where('ord_orbi_id', $sd_bill->sdob_orbi_id)
->get(['ord_order_number', 'ord_actual_price', 'ord_id']);
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data]);
}
$bill_data = DB::table('sd_order_bill')
->where('sdob_id', $request['sdob_id'])
->first(['sdob_sd_bill_bumber', 'sdob_sd_bill_price', 'sdob_orbi_id', 'sdob_start_time', 'sdob_end_time', 'sdob_bill_price', 'sdob_orbi_number']);
// 获取当前操作账号信息
$user_infos = Common::getUserInfo($request['api_token']);
$user_info = CommonService::dataToArray($user_infos);
$shop_id = $user_info['shop_superior_id'] ??$user_info['adm_shop_id'];
if($shop_id == 0){
$shop_id = $user_info['adm_shop_id'];
}
DB::beginTransaction();
$orbi_id = DB::table('sd_order_bill')
->where('sdob_id', $request['sdob_id'])
->value('sdob_orbi_id');
if(empty($orbi_id)){
// 2.订单账单表新增一条数据
// $number = 'DZ' . time() . rand(10000000, 99999999);
$number = $bill_data->sdob_orbi_number;
$data['sdob_orbi_id'] = $number;//本系统账单id
$add_data['orbi_cid'] = $user_info['adm_cid'];
$add_data['orbi_shop_id'] = $user_info['adm_shop_id'];
$add_data['orbi_superior_shop_id'] = $shop_id;
$add_data['orbi_number'] = $number;//账单编号
$add_data['orbi_start_time'] = $bill_data->sdob_start_time;//开始日期
$add_data['orbi_end_time'] = $bill_data->sdob_end_time;//结束日期
$add_data['orbi_state'] = 3; //待审核
$add_data['orbi_type'] = 3; //类型:1会员零售2客户单位3速电网单4虚拟加盟店5加盟店
$add_data['orbi_create_type'] = 2; //账单生成类型1手动生成2速电同步生成
$order_number = [];//订单号(速电派工单号)
// 查询速电同步账单详情表
$sobd_id = DB::table('sd_order_bill_details')
->where('sobd_sdob_id', $request['sdob_id'])
->select('sobd_id', 'sobd_sdob_id', 'sobd_order_number', 'sobd_ord_order_number', 'sobd_ord_id', 'sobd_actual_price')
->get()->toArray();
$sobd_id = json_decode(json_encode($sobd_id), true);
foreach ($sobd_id as $key => $value) {
$order_number[] = $value['sobd_order_number'];//订单号(速电派工单号)
$sd_order_detail[$value['sobd_order_number']] = $value;
}
$order_count = count($sobd_id);
$add_data['orbi_order_amount'] = $order_count;
// 根据速电工单号(第三方系统单号)查询订单数据
$order_info = DB::table('order')
->whereIn('ord_other_system_number', $order_number)
->where('ord_delete', 1)
// ->where('ord_state', 1) //未结算
->whereIn('ord_wor_state', [4, 5, 8]) //无工单 已完成 撤销订单
->select('ord_goods_quantity', 'ord_collection_price', 'ord_actual_price', 'ord_state', 'ord_service_type', 'ord_plus_minus', 'ord_id', 'ord_other_system_number', 'ord_order_number')
->get()->toArray();
$order_info = json_decode(json_encode($order_info), true);
$add_data['orbi_collection_price'] = 0; //代收金额
$add_data['orbi_goods_sum'] = 0; // 商品总量
$original_number = []; //原始id,更改应收账款数据使用
$ord_id = [];
$sys_order_number = [];
foreach ($order_info as $key => $value) {
$ord_id[] = $value['ord_id'];
$sys_order_number[] = $value['ord_other_system_number'];
$add_data['orbi_collection_price'] += $value['ord_collection_price']; //代收金额
$add_data['orbi_goods_sum'] += $value['ord_goods_quantity'];//商品总量
foreach ($sobd_id as $k => $v) {
if ($value['ord_other_system_number'] == $v['sobd_order_number']) {
$sobd_id[$k]['order_number'] = $value['ord_order_number']; //本系统的订单单号
$sobd_id[$k]['order_id'] = $value['ord_id']; //本系统的订单id
}
}
}
// 结算金额
$goods_price = $bill_data->sdob_bill_price;
// 如果是正数
if ($goods_price >= 0) {
$plus_minus = 1;
} else {
$plus_minus = 2;
}
$add_data['orbi_collection_price'] = 0; //代收金额为0
$add_data['orbi_plus_minus'] = $plus_minus; //正数
$add_data['orbi_state'] = 1; //账单状态1.未结款2.已结款3.待审核4.已驳回5.部分结款
$add_data['orbi_merge_state'] = 2; //1是2否
$add_data['orbi_total_price'] = $goods_price; //合计金额(单位:分)订单的结算
$add_data['orbi_bill_price'] = $goods_price; //结算金额(单位:分)订单结算金额:商品总金额-回收总金额
$add_data['orbi_actual_price'] = $goods_price; //实收金额(单位:分)订单结算金额-代收金额,实际应收金额
$add_data['orbi_sd_affirm'] = 1; //速电账单确认状态 0未确认 1已确认
$orbi_id = DB::table('order_bill')->insertGetId($add_data);
if (!empty($order_info)) {
// 3.修改订单表 账单id
$sql = 'UPDATE `faster_order` SET ';
$ord_orbi_id = ''; //账单id
$ord_state = ''; //更改结算状态
$update_time = ''; //调货时间
$ord_id_str = "";
foreach ($ord_id as $key => $value) {
// 更改账单id
$ord_orbi_id = $ord_orbi_id . ' WHEN ' . $value;
$ord_orbi_id = $ord_orbi_id . ' THEN ' . $orbi_id;
// 更改结算状态
$ord_state = $ord_state . ' WHEN ' . $value;
$ord_state = $ord_state . ' THEN 2';
// 更改时间
$update_time = $update_time . ' WHEN ' . $value;
$update_time = $update_time . ' THEN "' . date('Y-m-d H:i:s') . '"';
//要更改的订单id
$ord_id_str = $ord_id_str . $value . ',';
}
$sql = $sql . ' `ord_orbi_id`= CASE `ord_id` ' . $ord_orbi_id . ' END,';
$sql = $sql . ' `ord_state`= CASE `ord_id` ' . $ord_state . ' END,';
$sql = $sql . ' `ord_update_time`= CASE `ord_id` ' . $update_time . ' END';
$sql = $sql . ' WHERE `ord_id` IN (' . trim($ord_id_str, ',') . ')';
$save_order = DB::update($sql);
} else {
$save_order = true;
}
// 5. 生成应收账单
/*$createBill = ReceivableBill::create(
$user_info, //用户信息
3, //类型:1.销售订单 2.预收款 3.订单账单 4.工单账单 5.采购账单 6.销售账单
0, //应收账款id
$orbi_id, //原始id(订单账单id)
$number, //应收账款单号/原始号(订单账单编号)
6, //客户类型:1.门店零售 2.来往单位
0, //会员id/来往单位id
'', //来往单位名称
$goods_price, //实收金额
date('Y-m-d H:i:s'), //结款时间
0, //会计科目id
0, //实际金额
0, //抹零金额
1, //状态:1.未核销 2.已核销
2, //应收账单id是否是自己 1.不是 2.是
'', //备注
0, //已收金额
'', //截止时间
$plus_minus, //金额正负
5, //显示类型:1订单收款 2受托代收(订单代收)3委托代收(工单代收)4工单费用(工单收款)5订单账单 6工单账单 7销售账单 8预收款
date('Y-m-d H:i:s'),
2 //是否合并代收:1是2否
);*/
// 6.账单下所有的订单为不统计状态
/*$statistics_type_update = DB::table('receivable_credit')
->where('recr_cid', $user_info->adm_cid)
->where('recr_shop_superior_id', $shop_id)
->where('recr_type', 3)
->where('recr_belongs_id', $orbi_id)
->update(['recr_statistics_type' => 2, 'recr_update_time' => date('Y-m-d H:i:s')]);
if ($statistics_type_update || $statistics_type_update === 0) {
} else {
DB::rollBack();
return response()->json(['code'=>203, 'msg'=>'生成账单失败']);
}*/
// 判断是否有本系统不存在的订单
$diff_number = array_diff($order_number, $sys_order_number);
if (!empty($diff_number)) {
foreach ($diff_number as $key => $value) {
$price = 0;
foreach ($sobd_id as $k => $v) {
if ($v['sobd_order_number'] == $value) {
$price = $v['sobd_actual_price'];
}
}
$rece[$key]['recr_cid'] = $user_info['adm_cid'];
$rece[$key]['recr_shop_id'] = $user_info['adm_shop_id'];
$rece[$key]['recr_shop_superior_id'] = $shop_id;
$rece[$key]['recr_type'] = 3; //类型:1.销售订单 2.预收款 3.订单账单 4.工单账单 5.采购账单 6.销售账单
$rece[$key]['recr_account_type'] = 5;
//$rece[$key]['recr_number_id'] = $createBill; //应收账单id
$rece[$key]['recr_belongs_id'] = $orbi_id; //应收账单id
// $rece[$key]['recr_original_id'] = $recr_original_id; //与类型所对应的id
$rece[$key]['recr_original_number'] = $value; //与类型所对应的单号
$rece[$key]['recr_client_type'] = 6; //客户类型:1.门店零售 2.来往单位
$rece[$key]['recr_client_id'] = 0; //会员id/来往单位id
$rece[$key]['recr_client_name'] = config('apisystem.sd_chan_info')['name']; //来往单位名称
$rece[$key]['recr_settle_price'] = $price; //结算金额
$rece[$key]['recr_actual_price'] = $price; //实际金额
$rece[$key]['recr_state'] = 1; //状态:1.未核销 2.已核销
$rece[$key]['recr_plus_minus'] = 1; //金额正负值
$rece[$key]['recr_bill_type'] = 2; //1系统单 2非系统单
}
//$recr_res = DB::table('receivable_credit')->insert($rece);
$recr_res = true;
} else {
$recr_res = true;
}
}else{
$recr_res = true;
$save_order = true;
$createBill = DB::table('order_bill')
->where('orbi_id',$orbi_id)
->update(['orbi_sd_affirm'=>1,'orbi_update_time'=>date('Y-m-d H:i:s')]);
}
// 1.修改速电同步账单表状态
$data['sdob_state'] = 1;//对比状态0未处理1已对比 2已撤销
$data['sdob_update_time'] = date('Y-m-d H:i:s');
$data['sdob_orbi_id'] = $orbi_id;//本系统账单id
// 1.修改速电同步账单表状态
$res = DB::table('sd_order_bill')
->where('sdob_id', $request['sdob_id'])
->update($data);
//20230724 修改订单应收应付 //1现金、2支付宝、3微信、4银行卡
$sd_detail_ret = DB::table('sd_order_bill_details')
->where('sobd_sdob_id', $request['sdob_id'])
->get()->toArray();
foreach ($sd_detail_ret as $key => $value) {
$sobd_order_number[] = $value->sobd_order_number;
$sd_order_detail[$value->sobd_order_number] = $value;
}
if(isset($sobd_order_number)){
$order_info = DB::table('order')
->whereIn('ord_other_system_number', $sobd_order_number)
->where('ord_delete', 1)
->select('ord_order_number','ord_other_system_number')
->get()->toArray();
if($order_info){
$order_info = CommonService::dataToArray($order_info);
$order_number_arr = CommonService::jointArrayKey($order_info,'ord_other_system_number');
foreach ($sobd_order_number as $number_key => $number_value){
$rec_info = DB::table('receivable_pay')
->where('recpay_original_number', $order_number_arr[$number_value]['ord_order_number'])
->first();
if($rec_info){
$sd_info = $sd_order_detail[$number_value];
//$rece_params['recpay_original_number'] = $number_value;//订单id
$rece_params['recpay_original_number'] = $order_number_arr[$number_value]['ord_order_number'];//订单id
$rece_params['recpay_receivable_price'] = $sd_info->sobd_actual_price / 100;//应收金额
$rece_params['recpay_actual_price'] = $sd_info->sobd_actual_price / 100;//实收金额
$rece_params['recpay_arrears_price'] = 0;//欠收金额
$rece_params['recpay_cost_price'] = 0;//成本
$rece_params['recpay_plus_minus'] = 1;
$rece_params['recpay_profit'] = $sd_info->sobd_actual_price / 100;//盈利金额
$rece_params['recpay_state'] = 2;
$rt = ReceivablePayService::edit($rece_params);
$rec_info = DB::table('order')
->where('ord_order_number', $order_number_arr[$number_value]['ord_order_number'])
->update(['ord_state'=>2,'ord_actual_price'=>$sd_info->sobd_actual_price,'ord_settlement_time'=>date('Y-m-d H:i:s'),'ord_payment_money'=>$sd_info->sobd_actual_price]);
}
}
}
}
if ($res && $orbi_id && $recr_res && $save_order) {
Common::addLog($user_infos, getRealIp($request), '账单对比', '确认', '速电账单确认:' . $bill_data->sdob_sd_bill_bumber . '成功');
if (config('apisystem.SYNC_STATE')) {
//$url = config('apisystem.sd_server_name') . '/index.php/Supply/dealWith';
$url = config('apiconnect.ZPTZ_URL') . '/index.php/api/supplychain/SupplyMz/dealWith';
$param['time'] = date('Y-m-d H:i:s'); //收货时间
$param['ip'] = getRealIp($request);
$param['apply_note'] = ''; //拒单备注
//$param['token'] = md5(md5($param['time'] . config('apisystem.sd_token'))); //token
$param['token'] = md5(md5($param['time'] . config('apiconnect.ZPTZ_TOKEN'))); //token
$param['wat_num'] = $bill_data->sdob_sd_bill_bumber; //速电账单号
$doPost_res = Common::doPost($param, $url, 2);
$doPost_res = json_decode($doPost_res);
if ($doPost_res->code != 200) {
DB::rollBack();
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'fail']);
}
}
DB::commit();
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'账单确认成功']);
} else {
DB::rollBack();
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'账单确认失败']);
}
}
// //驳回
// public function reject(Request $request)
// {
// if(empty($request['sdob_id'])){
// return response()->json(['code'=> 500,'msg'=>'error','data'=>'参数错误']);
// }
// return response()->json(['code'=> 500,'msg'=>'error','data'=>'此功能暂时废弃']);
// $sd_data = DB::table('sd_order_bill')
// ->where('sdob_id',$request['sdob_id'])
// ->first(['sdob_sd_bill_bumber','sdob_orbi_id']);
// // 获取当前操作账号信息
// $user_info = Common::getUserInfo($request['api_token']);
// $data['sdob_update_time'] = date('Y-m-d H:i:s');
// $data['sdob_state'] = 1;
// $orbi_info = DB::table('order_bill')
// ->where('orbi_id', $sd_data->sdob_orbi_id)
// ->first(['orbi_state','orbi_type']);
// if($orbi_info->orbi_state != 1){
// return response()->json(['code'=> 500,'msg'=>'error','data'=>'此账单已结款不能驳回']);
// }
// $more_id = DB::table('money_record')
// ->where('more_orbi_id',$sd_data->sdob_orbi_id)
// ->value('more_id');
// if(!empty($more_id)){
// return response()->json(['code'=> 500,'msg'=>'error','data'=>'此账单已结款不能驳回']);
// }
// DB::beginTransaction();
// //删除速电账单
// $sdob_res = DB::table('sd_order_bill')
// ->where('sdob_id',$request['sdob_id'])
// ->delete();
// $sobd_res = DB::table('sd_order_bill_details')
// ->where('sobd_sdob_id',$request['sdob_id'])
// ->delete();
// //删除该账单
// $orbi_res = DB::table('order_bill')
// ->where('orbi_id', $sd_data->sdob_orbi_id)
// ->delete();
// //删除已生成的应收账单
// $rece_res = DB::table('receivable_credit')
// ->where('recr_original_id', $sd_data->sdob_orbi_id)
// ->delete();
// //把所属账单id修改成0
// $rece_two = DB::table('receivable_credit')
// ->where('recr_belongs_id', $sd_data->sdob_orbi_id)
// ->update(['recr_belongs_id'=>0,'recr_update_time'=>date('Y-m-d H:i:s')]);
// $order_data['ord_update_time'] = date('Y-m-d H:i:s');
// $order_data['ord_orbi_id'] = 0;
// $order_data['ord_state'] = 1;
// $ord_res = DB::table('order')
// ->where('ord_orbi_id', $sd_data->sdob_orbi_id)
// ->update($order_data);
// if ($sdob_res && $sobd_res && $orbi_res && $ord_res && $rece_res && $rece_two) {
// Common::addLog($user_info, getRealIp($request), '账单对比', '驳回', '速电账单驳回:'.$sd_data->sdob_sd_bill_bumber.'成功');
// if(config('apisystem.SYNC_STATE') && $orbi_info->orbi_type == 3){
// $url = config('apisystem.sd_server_name').'/index.php/Supply/operation';
// $param['time'] = date('Y-m-d H:i:s');//收货时间
// $param['ip'] = getRealIp($request);
// $param['apply_note'] = $request['remark'];//拒单备注
// $param['token'] = md5(md5($param['time'].config('apisystem.sd_token')));//token
// $param['wat_num'] = $sd_data->sdob_sd_bill_bumber;//速电账单号
// $doPost_res = Common::doPost($param,$url,2);
// $doPost_res = json_decode($doPost_res);
// if($doPost_res->code != 200){
// DB::rollBack();
// return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'失败']);
// }
// }
// DB::commit();
// return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'账单驳回成功']);
// } else {
// DB::rollBack();
// return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'账单驳回失败']);
// }
// }
// 速电驳回
public function reject(Request $request)
{
// 接收数据流
$request = file_get_contents("php://input");
// 解析
Common::write_log($request, 2);
$request = json_decode($request, true);
$sd_data = DB::table('sd_order_bill')
->where('sdob_sd_bill_bumber', $request['sd_bill_bumber'])
->where('sdob_state', '!=', 2)
->first(['sdob_sd_bill_bumber', 'sdob_orbi_id', 'sdob_id']);
if (empty($sd_data)) {
return response()->json(['code'=>203, 'msg'=>'结算单号错误']);
}
$more_id = DB::table('money_record')
->where('more_orbi_id', $sd_data->sdob_orbi_id)
->value('more_id');
if (!empty($more_id)) {
return response()->json(['code'=>203, 'msg'=>'此账单已结款不能驳回']);
}
$orbi_info = DB::table('order_bill')
->where('orbi_id', $sd_data->sdob_orbi_id)
->first(['orbi_state', 'orbi_type']);
if ($orbi_info->orbi_state != 1) {
return response()->json(['code'=>203, 'msg'=>'此账单已结款不能驳回']);
}
DB::beginTransaction();
//删除速电账单
$sdob_res = DB::table('sd_order_bill')
->where('sdob_id', $sd_data->sdob_id)
->update(['sdob_state' => 2, 'sdob_update_time' => date('Y-m-d H:i:s')]);
//删除该账单
$orbi_res = DB::table('order_bill')
->where('orbi_id', $sd_data->sdob_orbi_id)
->delete();
//删除已生成的应收账单
$rece_res = DB::table('receivable_credit')
->where('recr_original_id', $sd_data->sdob_orbi_id)
->delete();
//把所属账单id修改成0
$rece_two = DB::table('receivable_credit')
->where('recr_belongs_id', $sd_data->sdob_orbi_id)
->update(['recr_belongs_id' => 0, 'recr_update_time' => date('Y-m-d H:i:s')]);
$order_data['ord_update_time'] = date('Y-m-d H:i:s');
$order_data['ord_orbi_id'] = 0;
$order_data['ord_state'] = 1;
DB::table('order')
->where('ord_orbi_id', $sd_data->sdob_orbi_id)
->update($order_data);
if ($sdob_res && $orbi_res && $rece_res && $rece_two) {
DB::commit();
return response()->json(['code'=>200, 'msg'=>'账单撤回成功']);
} else {
DB::rollBack();
return response()->json(['code'=>203, 'msg'=>'账单撤回失败']);
}
}
// 查看
public function look(Request $request)
{
if (empty($request['sdob_id'])) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误']);
}
$sd_bill = DB::table('sd_order_bill')
->where('sdob_id', $request['sdob_id'])
->first(['sdob_sd_bill_bumber', 'sdob_start_time', 'sdob_end_time', 'sdob_bill_price', 'sdob_orbi_id', 'sdob_shop_name']);
$data['sd_order'] = DB::table('sd_order_bill_details')
->where('sobd_sdob_id', $request['sdob_id'])
->get(['sobd_order_number', 'sobd_actual_price', 'sobd_relative_price', 'sobd_ord_id', 'sobd_details_price', 'sobd_car_owner_name']);
foreach ($data['sd_order'] as $key => $value) {
$data['sd_order'][$key]->sobd_details_price = json_decode($value->sobd_details_price);
}
$data['mk_order'] = DB::table('order')
->where('ord_orbi_id', $sd_bill->sdob_orbi_id)
->get(['ord_order_number', 'ord_actual_price', 'ord_id']);
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$data]);
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
namespace App\Http\Controllers\Api\AccountManage;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountManage\VerifyProcurementBillController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
use App\Http\Models\Api\ReceivableBill;
use App\Http\Models\Api\AccountingSettlement;
use App\Http\Models\Api\AccountSubject;
class ProcurementBillController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('procurement_bill')
->where('prbi_cid', $user_info->adm_cid)
->where('prbi_superior_shop_id', $shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['prbi_state'])) {
$query->where('prbi_state', $search_data['prbi_state']);
}
}) //账单状态
->where(function($query) use($search_data) {
if (!empty($search_data['prbi_number'])) {
$query->where('prbi_number', 'like', $search_data['prbi_number'].'%' );
}
}) //账单编号
->where(function($query) use($search_data) {
if (!empty($search_data['prbi_audit_adm_id'])) {
$query->where('prbi_audit_adm_id', $search_data['prbi_audit_adm_id']);
}
}) //审核人id
->where(function($query) use($search_data) {
if (!empty($search_data['prbi_payment_way'])) {
$query->where('prbi_payment_way', $search_data['prbi_payment_way']);
}
}) //付款方式
->where(function($query) use($search_data) {
if (!empty($search_data['prbi_payment_time'])) {
$query->where('prbi_payment_time', 'like', $search_data['prbi_payment_time'].'%' );
}
}) //付款时间
->where(function($query) use($search_data) {
if (!empty($search_data['prbi_remark'])) {
$query->where('prbi_remark', 'like', $search_data['prbi_remark'].'%' );
}
}) //备注
->where(function($query) use($search_data) {
if (!empty($search_data['prbi_client_id'])) {
$query->where('prbi_type', 2 )
->where('prbi_client_id', $search_data['prbi_client_id'] );
}
}) //客户单位
->select('prbi_id', 'prbi_number', 'prbi_start_time', 'prbi_end_time', 'prbi_wor_amount',
'prbi_bill_price', 'prbi_payment_time', 'prbi_payment_way',
'prbi_actual_price', 'prbi_state', 'prbi_audit_time', 'prbi_audit_adm_id',
'prbi_create_adm_id', 'prbi_remark', 'prbi_client_id', 'prbi_type')
->orderBy('prbi_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
$mem_id = [];
$channel_id = [];
foreach ($list_items as $key => $value) {
$adm_id[] = $value->prbi_create_adm_id;
$adm_id[] = $value->prbi_audit_adm_id;
if($value->prbi_type == 1){
// 会员
$mem_id[] = $value->prbi_client_id;
}else{
// 客户单位
$channel_id[] = $value->prbi_client_id;
}
}
$adm_id = array_unique($adm_id);
$mem_id = array_unique($mem_id);
$channel_id = array_unique($channel_id);
// 查找账号id对应的账号姓名
$find_admin = DB::table('admin')
->whereIn('adm_id', $adm_id)
->get(['adm_id', 'adm_name']);
// 查找所对应的 会员信息
$find_mem = DB::table('member')
->whereIn('mem_id', $mem_id)
->get(['mem_id','mem_name','mem_phone','mem_address']);
// 查找所对应的 客户单位信息
$find_channel = DB::table('channel_unit')
->whereIn('chun_id', $channel_id)
->get(['chun_id','chun_unit_name','chun_name','chun_phone','chun_address']);
}else{
$find_admin = [];
$find_mem = [];
$find_channel = [];
}
$state_count = DB::table('procurement_bill')
->where('prbi_cid', $user_info->adm_cid)
->where('prbi_superior_shop_id', $shop_id)
->select(DB::raw('count(*) as count, prbi_state'))
->groupBy('prbi_state')
->get();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['find_admin'] = $find_admin; //返回数据
$data_info['state_count'] = $state_count; //返回数据
$data_info['find_mem'] = $find_mem; //会员信息
$data_info['find_channel'] = $find_channel; //客户单位信息
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 单量
public function billNumber(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->billNumberValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
if($request['type'] == 1){
// 账单信息
$bill = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->first(['prbi_id','prbi_number','prbi_start_time','prbi_end_time','prbi_create_time','prbi_create_adm_id',
'prbi_wor_amount','prbi_bill_price','prbi_actual_price','prbi_type','prbi_client_id']);
if($bill) {
if($bill->prbi_type == 2){
// 来往单位
$bill->prbi_client_name = DB::table('channel_unit')
->where('chun_id',$bill->prbi_client_id)
->value('chun_unit_name');
}else{
// 客户名称
$bill->prbi_client_name = DB::table('admin')
->where('adm_id',$bill->prbi_client_id)
->value('adm_name');
}
return response()->json(['code'=> 200,'msg'=>'success','data'=>$bill]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}else{
$list_data = DB::table('procurement as a')
->leftJoin('warehouse as b', 'b.ware_id', '=', 'a.proc_ware_id')
->leftJoin('procurement_client as c', 'c.prcl_proc_id', '=', 'a.proc_id')
->where('proc_cid', $user_info->adm_cid)
->where('proc_superior_shop_id', $shop_id)
->where('proc_prbi_id', $request['prbi_id'])
->where(function($query) use($search_data) {
if (!empty($search_data['proc_number'])) {
$query->where('proc_number', 'like', $search_data['proc_number'].'%' );
}
}) //订单编号
->where(function($query) use($search_data) {
if (!empty($search_data['prcl_name'])) {
$query->where('prcl_name', 'like', '%'.$search_data['prcl_name'].'%' );
}
}) //客户姓名
->where(function($query) use($search_data) {
if (!empty($search_data['prcl_phone'])) {
$query->where('prcl_phone', 'like', '%'.$search_data['prcl_phone'].'%' );
}
}) //客户电话
->where(function($query) use($search_data) {
if (!empty($search_data['prcl_address'])) {
$query->where('prcl_address', 'like', $search_data['prcl_address'].'%' );
}
}) //客户地址
->select('proc_id', 'proc_number', 'proc_state', 'proc_actual_count as proc_count', 'proc_adm_id', 'proc_audit_id',
'proc_remark', 'proc_data', 'proc_create_time', 'prcl_channel_unit', 'prcl_name',
'prcl_phone', 'prcl_address', 'ware_name', 'proc_actual_price')
->orderBy('proc_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
// 查找账号id
if(empty($list_items)){
$adm_id = [];
}else{
foreach ($list_items as $key => $value) {
if ($value->proc_adm_id) {
$adm_id[] = $value->proc_adm_id;
}
if ($value->proc_audit_id) {
$adm_id[] = $value->proc_audit_id;
}
if ($value->proc_data) {
$value->proc_data = json_decode($value->proc_data, true);
}
}
}
$adm_id = array_unique($adm_id);
// 查找账号id对应的账号姓名
$find_admin = DB::table('admin')
->whereIn('adm_id', $adm_id)
->select('adm_id', 'adm_name')
->get();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_data->items(); //返回数据
$data_info['find_admin'] = $find_admin; //返回账号姓名
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
}
// 结款
public function settleAccounts(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->getInfoValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$prbi_data = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->first(['prbi_number', 'prbi_state', 'prbi_start_time', 'prbi_end_time',
'prbi_create_time', 'prbi_create_adm_id', 'prbi_wor_amount', 'prbi_bill_price',
'prbi_client_id', 'prbi_type', 'prbi_goods_sum','prbi_receive_price',
'prbi_total_price', 'prbi_collection_price','prbi_img']);
if(empty($prbi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($request['type'] == 1){
// 获取到创建人姓名
$prbi_data->prbi_create_adm_name = DB::table('admin')
->where('adm_id',$prbi_data->prbi_create_adm_id)
->value('adm_name');
// 获取客户单位信息
if($prbi_data->prbi_type == 1){
// 会员
$member = DB::table('member')
->where('mem_id',$prbi_data->prbi_client_id)
->first(['mem_name','mem_phone','mem_address']);
$prbi_data->unit_name = '';
$prbi_data->adm_name = $member->mem_name;
$prbi_data->adm_phone = $member->mem_phone;
$prbi_data->adm_address = $member->mem_address;
}else{
// 客户单位
$channel = DB::table('channel_unit')
->where('chun_id',$prbi_data->prbi_client_id)
->first(['chun_unit_name','chun_name','chun_phone','chun_address']);
$prbi_data->unit_name = $channel->chun_unit_name;
$prbi_data->adm_name = $channel->chun_name;
$prbi_data->adm_phone = $channel->chun_phone;
$prbi_data->adm_address = $channel->chun_address;
}
return response()->json(['code'=> 200,'msg'=>'success','data'=>$prbi_data]);
}
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->settleAccountsValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$prbi_actual_price = $request['prbi_actual_price'] * 100; //实收金额
$zero_price = $request['zero_price'] ? $request['zero_price']*100 : 0; //抹零金额
// 还应收金额
$surplus_price = $prbi_data->prbi_bill_price-$prbi_data->prbi_receive_price;
if($prbi_actual_price > $surplus_price){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'实收金额不得大于还应收金额']);
}
$few = 0;
$img = '';
foreach ($request['prbi_img'] as $key => $value) {
// 调用全局函数 上传图片
$img .= uploadBase64Img($value).',';
$few++;
}
if($few == 0){
return response()->json(['code'=> 500, 'msg'=>'最少上传一张图片', 'data'=>'{}']);
}
if($few > 6){
return response()->json(['code'=> 500, 'msg'=>'最多上传六张图片', 'data'=>'{}']);
}
$img = $prbi_data->prbi_img.','.$img;
$img = rtrim($img, ',');
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 获取来往单位名称
if($request['prbi_type'] == 1){
$client_name = '';
}else{
$client_name = DB::table('channel_unit')
->where('chun_id',$request['prbi_client_id'])
->value('chun_unit_name');
}
DB::beginTransaction();
// 提交的实收金额+抹零金额 == 剩余可结款金额,账单已全部结款
if (($prbi_actual_price + $zero_price) == $surplus_price) {
// $prbi_state 账单状态1.未结款2.已结款3.待审核4.已驳回5.部分结款
$prbi_state = 2;
}else{
$prbi_state = 5;
}
// 修改采购账单表
$update_state = DB::update('UPDATE `faster_procurement_bill` SET `prbi_receive_price`=`prbi_receive_price`+'.$prbi_actual_price.', `prbi_zero_price`=`prbi_zero_price`+'.$zero_price.' ,`prbi_actual_price`=`prbi_actual_price`+'.$prbi_actual_price.' ,`prbi_state`= '.$prbi_state.' ,`prbi_remark`= "'.$request['prbi_remark'].'" ,`prbi_payee_id`= '.$user_info->adm_id.',`prbi_img`= "'.$img.'" ,`prbi_payment_time`= "'.date('Y-m-d H:i:s').'" ,`prbi_update_time`= "'.date('Y-m-d H:i:s').'" WHERE `prbi_id`=?',[$request['prbi_id']]);
// 查询出账单对应的应收账款id
$find_acpa = DB::table('accounts_payable')
->where('acpa_cid',$user_info->adm_cid)
->where('acpa_shop_superior_id',$shop_id)
->where('acpa_type',2)
->where('acpa_original_id',$request['prbi_id'])
->select('acpa_id','acpa_remark')
->first();
// 6. 更改账单的应收账款金额
$acpa_edit_data['acpa_actual_price'] = $prbi_actual_price;
$acpa_edit_data['acpa_zero_price'] = $zero_price;
$acpa_edit_data['acpa_yet_receipt'] = $prbi_data->prbi_receive_price + $prbi_actual_price;
$acpa_edit_data['acpa_remark'] = $find_acpa->acpa_remark.$request->input('prbi_remark','');
$acpa_edit_data['acpa_update_time'] = date('Y-m-d H:i:s');
$createBill = DB::table('accounts_payable')
->where('acpa_cid',$user_info->adm_cid)
->where('acpa_shop_superior_id',$shop_id)
->where('acpa_type',2)
->where('acpa_id',$find_acpa->acpa_id)
->update($acpa_edit_data);
// 预付款抵账(减预付款金额)
if($request['prbi_payment_type'] == 3){
// 实收金额
$subtract = DB::table('accounts_payable')
->where('acpa_id',$request['acpa_id'])
->decrement('acpa_actual_price',$prbi_actual_price);
$add_data['acde_advance_id'] = $request['acpa_id']; //预付款id
$add_data['acde_acpa_id'] = $createBill; //账单id
$details_data = DB::table('accounts_details')->insert($add_data);
// $AccountSubject = true;
}else{
$subtract = true;
$details_data = true;
// // 编辑科目管理表
// $AccountSubject = AccountSubject::Subject(
// $user_info, // [用户信息]
// 2, // [类型:1借2贷]
// $prbi_actual_price, // [金额]
// $request['acti_id'] // [科目id]
// );
}
$acti_closing_account = DB::table('account_title')
->where('acti_id',$request['acti_id'])
->value('acti_closing_account');
if($prbi_actual_price > $acti_closing_account){
DB::rollBack();
return response()->json(["code"=>500,'msg'=>'error','data'=>'科目余额不足']);
}
// 添加结款明细
$AccountingSettlement = AccountingSettlement::add(
$user_info, // [用户信息]
4, // [单据类型1订单2订单账单3工单账单4采购账单5销售账单6预收款]
$request['prbi_id'], // [与单据类型对应的id]
$prbi_data->prbi_number, // [与单据类型对应的单号]
$prbi_data->prbi_type, // [买家类型1门店零售2来往单位]
$prbi_data->prbi_client_id, // [会员/客户id]
$client_name, // [来往单位名称]
$request['acti_id'], // [会计科目id]
2, // [类型1收入2支出]
$prbi_actual_price, // [实际金额](此次的实收金额)
$surplus_price, // [合计金额](此次的应收金额)
$surplus_price-$prbi_actual_price-$zero_price, // [欠收金额](此次结款后还应收金额)
$zero_price, // [抹零金额]
$request['prbi_remark'] ? $request['prbi_remark'] : '' // [备注]
);
if($update_state && $createBill && $AccountingSettlement && $subtract && $details_data) {
$user_info = Common::getUserInfo($request['api_token']);
Common::addLog($user_info, getRealIp($request), '采购账单','结款',$prbi_data->prbi_number.'结款成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'结款成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'结款失败']);
}
}
// 查看
public function lookInfo(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->delValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$prbi_data = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->first(['prbi_number', 'prbi_state', 'prbi_start_time', 'prbi_end_time',
'prbi_create_time', 'prbi_create_adm_id', 'prbi_wor_amount', 'prbi_bill_price',
'prbi_client_id', 'prbi_type', 'prbi_goods_sum' ,'prbi_total_price',
'prbi_collection_price', 'prbi_bill_price', 'prbi_audit_time', 'prbi_audit_adm_id',
'prbi_payment_time', 'prbi_payee_id', 'prbi_payment_way', 'prbi_actual_price',
'prbi_remark', 'prbi_img', 'prbi_zero_price']);
if(empty($prbi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
// 获取到创建人姓名
$prbi_data->prbi_create_adm_name = DB::table('admin')
->where('adm_id',$prbi_data->prbi_create_adm_id)
->value('adm_name');
// 获取到审核人姓名
$prbi_data->prbi_audit_adm_name = DB::table('admin')
->where('adm_id',$prbi_data->prbi_audit_adm_id)
->value('adm_name');
// 获取到收款人姓名
$prbi_data->prbi_payee_name = DB::table('admin')
->where('adm_id',$prbi_data->prbi_payee_id)
->value('adm_name');
// 获取客户单位信息
if($prbi_data->prbi_type == 1){
// 会员
$member = DB::table('member')
->where('mem_id',$prbi_data->prbi_client_id)
->first(['mem_name','mem_phone','mem_address']);
$prbi_data->unit_name = '';
$prbi_data->adm_name = $member->mem_name;
$prbi_data->adm_phone = $member->mem_phone;
$prbi_data->adm_address = $member->mem_address;
}else{
// 客户单位
$channel = DB::table('channel_unit')
->where('chun_id',$prbi_data->prbi_client_id)
->first(['chun_unit_name','chun_name','chun_phone','chun_address']);
$prbi_data->unit_name = $channel->chun_unit_name;
$prbi_data->adm_name = $channel->chun_name;
$prbi_data->adm_phone = $channel->chun_phone;
$prbi_data->adm_address = $channel->chun_address;
}
return response()->json(['code'=> 200,'msg'=>'success','data'=>$prbi_data]);
}
// 审核
public function audit(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->auditValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$prbi_data = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->first(['prbi_number', 'prbi_state', 'prbi_start_time', 'prbi_end_time',
'prbi_create_time', 'prbi_create_adm_id', 'prbi_wor_amount', 'prbi_bill_price',
'prbi_client_id', 'prbi_type', 'prbi_goods_sum']);
if(empty($prbi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($prbi_data->prbi_state != 3){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'待审核状态下才可以审核']);
}
if($request['type'] == 1){
// 获取到创建人姓名
$prbi_data->prbi_create_adm_name = DB::table('admin')
->where('adm_id',$prbi_data->prbi_create_adm_id)
->value('adm_name');
// 获取客户单位信息
if($prbi_data->prbi_type == 1){
// 会员
$member = DB::table('member')
->where('mem_id',$prbi_data->prbi_client_id)
->first(['mem_name','mem_phone','mem_address']);
$prbi_data->unit_name = '';
$prbi_data->adm_name = $member->mem_name;
$prbi_data->adm_phone = $member->mem_phone;
$prbi_data->adm_address = $member->mem_address;
}else{
// 客户单位
$channel = DB::table('channel_unit')
->where('chun_id',$prbi_data->prbi_client_id)
->first(['chun_unit_name','chun_name','chun_phone','chun_address']);
$prbi_data->unit_name = $channel->chun_unit_name;
$prbi_data->adm_name = $channel->chun_name;
$prbi_data->adm_phone = $channel->chun_phone;
$prbi_data->adm_address = $channel->chun_address;
}
$proc_data = DB::table('procurement as p')
->leftJoin('admin as a', 'p.proc_adm_id', '=', 'a.adm_id')
->where('proc_prbi_id',$request['prbi_id'])
->get(['proc_create_time', 'proc_number', 'proc_adm_id',
'proc_price', 'proc_actual_price', 'adm_name as proc_adm_name']);
$data['prbi_data'] = $prbi_data;
$data['proc_data'] = $proc_data;
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data]);
}
$user_info = Common::getUserInfo($request['api_token']);
DB::beginTransaction();
$update_data['prbi_state'] = $request['prbi_state'];
$update_data['prbi_audit_time'] = date('Y-m-d H:i:s'); //审核时间
$update_data['prbi_audit_adm_id'] = $user_info->adm_id; //审核人
$update_data['prbi_update_time'] = date('Y-m-d H:i:s');
$update_state = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->update($update_data);
// 获取客户单位名称
if($prbi_data->prbi_type == 1){
$client_name = '';
}else{
$client_name = DB::table('channel_unit')
->where('chun_id',$prbi_data->prbi_client_id)
->value('chun_unit_name');
}
//如果是同意状态
if($request['prbi_state'] == 1){
// 6. 生成应付账单
$createBill = ReceivableBill::addAccounts(
$user_info, //用户信息
2, //类型:1.预付款 2.采购账单
0, //应收账款id
$request['prbi_id'], //原始id(订单账单id)
$prbi_data->prbi_number, //应收账款单号/原始号(订单账单编号)
$prbi_data->prbi_type, //客户类型:1.门店零售 2.来往单位
$prbi_data->prbi_client_id, //会员id/来往单位id
$client_name, //来往单位名称
$prbi_data->prbi_bill_price, //结算金额
date('Y-m-d H:i:s'), //结款时间
0, //会计科目id
0, //实际金额
0, //抹零金额
1, //状态:1.未核销 2.已核销
2, //应收账单id是否是自己 1.不是 2.是
'', //备注
0 //已付金额
);
}else{
$createBill = true;
}
if($update_state && $createBill) {
Common::addLog($user_info, getRealIp($request), '订单账单','审核',$prbi_data->prbi_number.'审核成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'审核成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'审核失败']);
}
}
// 删除(做成了真删)
public function del(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->delValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$prbi_data = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->first(['prbi_number', 'prbi_state','prbi_type', 'prbi_client_id', 'prbi_bill_price']);
if(empty($prbi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($prbi_data->prbi_state != 4){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'已驳回的账单才可以删除']);
}
DB::beginTransaction();
// 1.删除账单表
$del_orbi = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->delete();
// 2.解除采购单与账单的绑定关系
$update_data['proc_prbi_id'] = 0;
$update_data['proc_update_time'] = date('Y-m-d H:i:s');
$update_state = DB::table('procurement')
->where('proc_prbi_id',$request['prbi_id'])
->update($update_data);
if($del_orbi && $update_state) {
$user_info = Common::getUserInfo($request['api_token']);
Common::addLog($user_info, getRealIp($request), '采购账单','删除',$prbi_data->prbi_number.'删除成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'删除成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'删除失败']);
}
}
// 搜索预付款id
public function advanceMoney(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->advanceMoneyValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 验证当前账单是否存在
$data = DB::table('accounts_payable')
->where('acpa_cid',$user_info->adm_cid)
->where('acpa_shop_superior_id',$shop_id)
->where('acpa_client_id',$request['client_id'])
->where('acpa_type',1)
->where('acpa_actual_price','!=',0)
->get(['acpa_id','acpa_actual_price','acpa_original_number']);
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data]);
}
// 反审核
public function cancelAudit(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->delValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$user_info = Common::getUserInfo($request['api_token']);
// 验证当前账单是否存在
$prbi_data = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->first(['prbi_number', 'prbi_state']);
if(empty($prbi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($prbi_data->prbi_state != 4 && $prbi_data->prbi_state != 1){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'已驳回或者未结款的账单才可以反审核']);
}
$update_data['prbi_state'] = 3; // 账单状态1.未结款 2.已结款 3.待审核 4.已驳回 5.部分结款
$update_data['prbi_update_time'] = date('Y-m-d H:i:s');
DB::beginTransaction();
// 1.修改状态
$update_state = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->update($update_data);
// 通过的账单 删除应付账款
if($prbi_data->prbi_state == 1){
$del_payable = DB::table('accounts_payable')
->where('acpa_type',2) //类型 2.采购账单
->where('acpa_original_number',$prbi_data->prbi_number) //与类型所对应的id
->delete();
$update_belongs = DB::table('accounts_payable')
->where('acpa_belongs_id',$request['prbi_id'])
->update(['acpa_belongs_id'=>0,'acpa_update_time'=>date('Y-m-d H:i:s')]);
}else{
$del_payable = true;
$update_belongs = true;
}
if($update_state && $del_payable && $update_belongs) {
Common::addLog($user_info, getRealIp($request), '采购账单','反审核',$prbi_data->prbi_number.'反审核成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'反审核成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'反审核失败']);
}
}
// 编辑
public function edit(Request $request)
{
// 验证数据
$verify_data = new VerifyProcurementBillController;
$error_message = $verify_data->editValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$user_info = Common::getUserInfo($request['api_token']);
// 1.解除该采购账单与原来采购入库的绑定关系
$relieve_data['proc_prbi_id'] = 0; //账单id改为0
$relieve_data['proc_update_time'] = date('Y-m-d H:i:s');
$relieve_relation = DB::table('procurement')
->where('proc_prbi_id',$request['prbi_id'])
->update($relieve_data);
// 2.重新绑定采购入库单与账单的关系
$sql = 'UPDATE `faster_procurement` SET ';
$proc_prbi_id = ''; //账单id
$update_time = ''; //调货时间
$proc_id = "";
foreach ($request['proc_id'] as $key => $value) {
// 更改账单id
$proc_prbi_id = $proc_prbi_id . ' WHEN ' .$value;
$proc_prbi_id = $proc_prbi_id . ' THEN ' .$request['prbi_id'];
// 更改时间
$update_time = $update_time . ' WHEN ' .$value;
$update_time = $update_time . ' THEN "' .date('Y-m-d H:i:s').'"';
//要更改的采购单id
$proc_id = $proc_id . $value.',';
}
$sql = $sql .' `proc_prbi_id`= CASE `proc_id` '.$proc_prbi_id.' END,';
$sql = $sql .' `proc_update_time`= CASE `proc_id` '.$update_time.' END';
$sql = $sql .' WHERE `proc_id` IN ('.trim($proc_id,',').')';
$save_procurement = DB::update($sql);
// 3.修改单量 改为待审核状态
$update_bill['prbi_wor_amount'] = count($request['proc_id']); //单量
$update_bill['prbi_state'] = 3; //3.待审核
$update_bill['prbi_update_time'] = date('Y-m-d H:i:s');
$bill_data = DB::table('procurement_bill')
->where('prbi_id',$request['prbi_id'])
->update($update_bill);
if($relieve_relation && $save_procurement && $bill_data) {
Common::addLog($user_info, getRealIp($request), '采购账单','编辑',$request['prbi_number'].'编辑成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'编辑成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'编辑失败']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountManage;
use Illuminate\Http\Request;
use App\Http\Models\Api\Common;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Http\Models\Api\ReceivableBill;
use App\Http\Models\Api\AccountingSettlement;
use App\Http\Controllers\Api\Verify\AccountManage\VerifySellBillController;
class SellBillController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifySellBillController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_ids = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('sell_bill')
->where('sebi_cid', $user_info->adm_cid)
->where(function($query) use($search_data) {
if (!empty($search_data['sebi_state'])) {
$query->where('sebi_state', $search_data['sebi_state']);
}
}) //账单状态
->where(function($query) use($search_data) {
if (!empty($search_data['sebi_payment_time'])) {
$query->where('sebi_payment_time', 'like', $search_data['sebi_payment_time'].'%' );
}
}) //结款时间
->where(function($query) use($search_data) {
if (!empty($search_data['sebi_number'])) {
$query->where('sebi_number', 'like', $search_data['sebi_number'].'%' );
}
}) //账单编号
->where(function($query) use($search_data) {
if (!empty($search_data['sebi_audit_adm_id'])) {
$query->where('sebi_audit_adm_id', $search_data['sebi_audit_adm_id']);
}
}) //审核人id
->where(function($query) use($search_data) {
if (!empty($search_data['sebi_payment_way'])) {
$query->where('sebi_payment_way', $search_data['sebi_payment_way']);
}
}) //结款方式
->where(function($query) use($search_data) {
if (!empty($search_data['sebi_remark'])) {
$query->where('sebi_remark', 'like', $search_data['sebi_remark'].'%' );
}
}) //备注
->where(function($query) use($search_data) {
if (!empty($search_data['sebi_client_id'])) {
$query->where('sebi_type', 2 )
->where('sebi_client_id', $search_data['sebi_client_id'] );
}
}) //客户单位
->select('sebi_id', 'sebi_number', 'sebi_start_time', 'sebi_end_time', 'sebi_wor_amount',
'sebi_bill_price', 'sebi_payment_time', 'sebi_payment_way', 'sebi_handle_adm_id',
'sebi_actual_price', 'sebi_state', 'sebi_audit_time', 'sebi_audit_adm_id',
'sebi_create_adm_id', 'sebi_remark', 'sebi_client_id', 'sebi_type','sebi_plus_minus')
->orderBy('sebi_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
$mem_id = [];
$channel_id = [];
foreach ($list_items as $key => $value) {
$adm_id[] = $value->sebi_create_adm_id;
$adm_id[] = $value->sebi_audit_adm_id;
$adm_id[] = $value->sebi_handle_adm_id;
if($value->sebi_type == 1){
// 会员
$mem_id[] = $value->sebi_client_id;
}else{
// 客户单位
$channel_id[] = $value->sebi_client_id;
}
}
$adm_id = array_unique($adm_id);
$mem_id = array_unique($mem_id);
$channel_id = array_unique($channel_id);
// 查找账号id对应的账号姓名
$find_admin = DB::table('admin')
->whereIn('adm_id', $adm_id)
->get(['adm_id', 'adm_name']);
// 查找所对应的 会员信息
$find_mem = DB::table('member')
->whereIn('mem_id', $mem_id)
->get(['mem_id','mem_name','mem_phone','mem_address']);
// 查找所对应的 客户单位信息
$find_channel = DB::table('channel_unit')
->whereIn('chun_id', $channel_id)
->get(['chun_id','chun_unit_name','chun_name','chun_phone','chun_address']);
}else{
$find_admin = [];
$find_mem = [];
$find_channel = [];
}
$state_count = DB::table('sell_bill')
->where('sebi_cid', $user_info->adm_cid)
->select(DB::raw('count(*) as count, sebi_state'))
->groupBy('sebi_state')
->get();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['find_admin'] = $find_admin; //返回数据
$data_info['state_count'] = $state_count; //返回数据
$data_info['find_mem'] = $find_mem; //会员信息
$data_info['find_channel'] = $find_channel; //客户单位信息
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 单量
public function billNumber(Request $request)
{
// 验证数据
$verify_data = new VerifySellBillController;
$error_message = $verify_data->billNumberValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
if($request['type'] == 1){
// 账单信息
$bill = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->first(['sebi_id','sebi_number','sebi_start_time','sebi_end_time','sebi_create_time','sebi_create_adm_id',
'sebi_wor_amount','sebi_bill_price','sebi_actual_price','sebi_type','sebi_client_id']);
if($bill) {
if($bill->sebi_type == 2){
// 来往单位
$bill->sebi_client_name = DB::table('channel_unit')
->where('chun_id',$bill->sebi_client_id)
->value('chun_unit_name');
}else{
// 客户名称
$bill->sebi_client_name = DB::table('admin')
->where('adm_id',$bill->sebi_client_id)
->value('adm_name');
}
return response()->json(['code'=> 200,'msg'=>'success','data'=>$bill]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}else{
$list_data = DB::table('sell as a')
->leftJoin('warehouse as b', 'b.ware_id', '=', 'a.sell_ware_id')
->leftJoin('sell_client as c', 'c.secl_sell_id', '=', 'a.sell_id')
->where('sell_cid', $user_info->adm_cid)
->where('sell_superior_shop_id', $shop_id)
->where('sell_sebi_id', $request['sebi_id'])
->where(function($query) use($search_data) {
if (!empty($search_data['sell_number'])) {
$query->where('sell_number', 'like', $search_data['sell_number'].'%' );
}
}) //编号
->where(function($query) use($search_data) {
if (!empty($search_data['secl_name'])) {
$query->where('secl_name', 'like', '%'.$search_data['secl_name'].'%' );
}
}) //客户名称
->where(function($query) use($search_data) {
if (!empty($search_data['secl_phone'])) {
$query->where('secl_phone', 'like', '%'.$search_data['secl_phone'].'%' );
}
}) //客户电话
->where(function($query) use($search_data) {
if (!empty($search_data['secl_address'])) {
$query->where('secl_address', 'like', $search_data['secl_address'].'%' );
}
}) //客户地址
->select('sell_id', 'sell_number', 'sell_state', 'sell_count', 'sell_adm_id', 'sell_remark',
'sell_data', 'sell_create_time', 'secl_channel_unit', 'secl_name', 'secl_phone',
'secl_address', 'ware_name', 'sell_actual_price')
->orderBy('sell_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if(empty($list_items)){
$find_admin = [];
$find_mem = [];
$find_channel = [];
}else{
$mem_id = [];
$channel_id = [];
foreach ($list_items as $key => $value) {
if ($value->sell_adm_id) {
$adm_id[] = $value->sell_adm_id;
}
if ($value->sell_data) {
$value->sell_data = json_decode($value->sell_data, true);
}
// if($value->wobi_type == 1){
// // 会员
// $mem_id[] = $value->wobi_client_id;
// }else{
// // 客户单位
// $channel_id[] = $value->wobi_client_id;
// }
}
$adm_id = array_unique($adm_id);
// $mem_id = array_unique($mem_id);
// $channel_id = array_unique($channel_id);
// 查找账号id对应的账号姓名
$find_admin = DB::table('admin')
->whereIn('adm_id', $adm_id)
->get(['adm_id', 'adm_name']);
// 查找所对应的 会员信息
// $find_mem = DB::table('member')
// ->whereIn('mem_id', $mem_id)
// ->get(['mem_name','mem_phone','mem_address']);
//
// // 查找所对应的 客户单位信息
// $find_channel = DB::table('channel_unit')
// ->whereIn('chun_id', $channel_id)
// ->get(['chun_unit_name','chun_name','chun_phone','chun_address']);
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['find_admin'] = $find_admin; //返回账号姓名
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success', 'data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
}
// 结款
public function settleAccounts(Request $request)
{
// 验证数据
$verify_data = new VerifySellBillController;
$error_message = $verify_data->getInfoValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$sebi_data = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->first(['sebi_number', 'sebi_state', 'sebi_start_time', 'sebi_end_time',
'sebi_create_time', 'sebi_create_adm_id', 'sebi_wor_amount', 'sebi_bill_price',
'sebi_client_id', 'sebi_type', 'sebi_goods_sum', 'sebi_collection_price',
'sebi_total_price', 'sebi_receive_price','sebi_img','sebi_plus_minus']);
if(empty($sebi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($request['type'] == 1){
// 获取到创建人姓名
$sebi_data->sebi_create_adm_name = DB::table('admin')
->where('adm_id',$sebi_data->sebi_create_adm_id)
->value('adm_name');
// 获取客户单位信息
if($sebi_data->sebi_type == 1){
// 会员
$member = DB::table('member')
->where('mem_id',$sebi_data->sebi_client_id)
->first(['mem_name','mem_phone','mem_address']);
$sebi_data->unit_name = '';
$sebi_data->adm_name = $member->mem_name;
$sebi_data->adm_phone = $member->mem_phone;
$sebi_data->adm_address = $member->mem_address;
}else{
// 客户单位
$channel = DB::table('channel_unit')
->where('chun_id',$sebi_data->sebi_client_id)
->first(['chun_unit_name','chun_name','chun_phone','chun_address']);
$sebi_data->unit_name = $channel->chun_unit_name;
$sebi_data->adm_name = $channel->chun_name;
$sebi_data->adm_phone = $channel->chun_phone;
$sebi_data->adm_address = $channel->chun_address;
}
return response()->json(['code'=> 200,'msg'=>'success','data'=>$sebi_data]);
}
// 验证数据
$verify_data = new VerifySellBillController;
$error_message = $verify_data->settleAccountsValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$sebi_actual_price = $request['sebi_actual_price'] * 100; //实收金额
$zero_price = $request->input('zero_price', 0) * 100; //抹零金额
// 还应收金额
$surplus_price = $sebi_data->sebi_bill_price - $sebi_data->sebi_receive_price;
if(($sebi_actual_price + $zero_price) > $surplus_price){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'实收金额不得大于结款金额']);
}
if ($request['sebi_payment_type'] == 3) {
// 预收款抵账不用上传图片
$img = '';
}else{
$few = 0;
$img = '';
foreach ($request['sebi_img'] as $key => $value) {
// 调用全局函数 上传图片
$img .= uploadBase64Img($value).',';
$few++;
}
if($few == 0){
return response()->json(['code'=> 500, 'msg'=>'最少上传一张图片', 'data'=>'{}']);
}
if($few > 6){
return response()->json(['code'=> 500, 'msg'=>'最多上传六张图片', 'data'=>'{}']);
}
}
$img = $sebi_data->sebi_img.','.$img;
$img = trim($img, ',');
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
DB::beginTransaction();
// 获取客户单位名称
if($sebi_data->sebi_type == 1){
// 获取零售客户姓名
$client_name = DB::table('member')
->where('mem_id',$request['orbi_client_id'])
->value('mem_name');
}else{
$client_name = DB::table('channel_unit')
->where('chun_id',$sebi_data->sebi_client_id)
->value('chun_unit_name');
}
// 判断账单状态
// 提交的实收金额+抹零金额 == 剩余可结款金额,账单已全部结款
if (($sebi_actual_price + $zero_price) == $surplus_price) {
// sebi_state 账单状态1.未结款2.已结款3.待审核4.已驳回5.部分结款
$sebi_state = 2;
}else{
$sebi_state = 5;
}
// 修改工单账单表 (加已收金额)
$update_bill = DB::update('UPDATE `faster_sell_bill` SET `sebi_receive_price`=`sebi_receive_price`+'.$sebi_actual_price.', `sebi_zero_price`=`sebi_zero_price`+'.$zero_price.' ,`sebi_actual_price`=`sebi_actual_price`+'.$sebi_actual_price.' ,`sebi_state`= '.$sebi_state.' ,`sebi_remark`= "'.$request['sebi_remark'].'" ,`sebi_payee_id`= '.$user_info->adm_id.' ,`sebi_img`= "'.$img.'" ,`sebi_payment_time`= "'.date('Y-m-d H:i:s').'" ,`sebi_update_time`= "'.date('Y-m-d H:i:s').'" WHERE `sebi_id`=?',[$request['sebi_id']] );
// 查询出账单对应的应收账款id
$find_recr = DB::table('receivable_credit')
->where('recr_cid',$user_info->adm_cid)
->where('recr_shop_superior_id',$shop_id)
->where('recr_type',6)
->where('recr_account_type',7)
->where('recr_belongs_id',0)
->where('recr_original_id',$request['sebi_id'])
->select('recr_id','recr_remark')
->first();
// 6. 更改账单的应收账款金额
$recr_edit_data['recr_actual_price'] = $sebi_actual_price;
$recr_edit_data['recr_zero_price'] = $zero_price;
$recr_edit_data['recr_yet_receipt'] = $sebi_data->sebi_receive_price + $sebi_actual_price;
$recr_edit_data['recr_remark'] = $find_recr->recr_remark.$request->input('sebi_remark','');
$recr_edit_data['recr_update_time'] = date('Y-m-d H:i:s');
$createBill = DB::table('receivable_credit')
->where('recr_cid',$user_info->adm_cid)
->where('recr_shop_superior_id',$shop_id)
->where('recr_type',6)
->where('recr_account_type',7)
->where('recr_id',$find_recr->recr_id)
->update($recr_edit_data);
// 添加结款明细
$AccountingSettlement = AccountingSettlement::add(
$user_info, // [用户信息]
5, // [单据类型1订单2订单账单3工单账单4采购账单5销售账单6预收款]
$request['sebi_id'], // [与单据类型对应的id]
$sebi_data->sebi_number, // [与单据类型对应的单号]
$sebi_data->sebi_type, // [买家类型1门店零售2来往单位]
$sebi_data->sebi_client_id, // [会员/客户id]
$client_name, // [来往单位名称]
$request->input('acti_id',0), // [会计科目id]
$sebi_data->sebi_plus_minus, // [类型1收入2支出]
$sebi_actual_price, // [实际金额](此次的实收金额)
$surplus_price, // [合计金额](此次的应收金额)
$surplus_price-$sebi_actual_price-$zero_price, // [欠收金额](此次结款后还应收金额)
$zero_price, // [抹零金额]
$recr_edit_data['recr_remark'], // [备注]
$request['sebi_payment_type'] // [结款类型1.抹零 2.分期结款 3.预收款抵账4正常]
);
// 预收款抵账(减预收款金额)
if($request['sebi_payment_type'] == 3){
// 预收款金额,实际金额减少,已收金额增加
$prepay_price = $request['sebi_actual_price'] * 100;
$subtract = DB::update('UPDATE `faster_receivable_credit` SET `recr_actual_price`=`recr_actual_price`-'.$prepay_price.', `recr_yet_receipt`=`recr_yet_receipt`+'.$prepay_price.' WHERE `recr_id`=?',[$request['recr_id']]);
$add_data['rede_advance_id'] = $request['recr_id']; //预付款的应收账款id
$add_data['rede_recr_id'] = $find_recr->recr_id; //账单应付账款id
$add_data['rede_acset_id'] = $AccountingSettlement; //预收款抵账的结款明细id
$details_data = DB::table('receivable_details')->insert($add_data);
}else{
$subtract = true;
$details_data = true;
}
if($createBill && $update_bill && $AccountingSettlement && $subtract && $details_data) {
Common::addLog($user_info, getRealIp($request), '销售账单','结款',$sebi_data->sebi_number.'结款成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'结款成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'结款失败']);
}
}
// 审核
public function audit(Request $request)
{
// 验证数据
$verify_data = new VerifySellBillController;
$error_message = $verify_data->auditValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$sebi_data = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->first(['sebi_number', 'sebi_state', 'sebi_start_time', 'sebi_end_time',
'sebi_create_time', 'sebi_create_adm_id', 'sebi_wor_amount', 'sebi_bill_price',
'sebi_client_id', 'sebi_type', 'sebi_goods_sum','sebi_actual_price']);
if(empty($sebi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($sebi_data->sebi_state != 3){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'待审核状态下才可以审核']);
}
if($request['type'] == 1){
// 获取到创建人姓名
$sebi_data->sebi_create_adm_name = DB::table('admin')
->where('adm_id',$sebi_data->sebi_create_adm_id)
->value('adm_name');
// 获取客户单位信息
if($sebi_data->sebi_type == 1){
// 会员
$member = DB::table('member')
->where('mem_id',$sebi_data->sebi_client_id)
->first(['mem_name','mem_phone','mem_address']);
$sebi_data->unit_name = '';
$sebi_data->adm_name = $member->mem_name;
$sebi_data->adm_phone = $member->mem_phone;
$sebi_data->adm_address = $member->mem_address;
}else{
// 客户单位
$channel = DB::table('channel_unit')
->where('chun_id',$sebi_data->sebi_client_id)
->first(['chun_unit_name','chun_name','chun_phone','chun_address']);
$sebi_data->unit_name = $channel->chun_unit_name;
$sebi_data->adm_name = $channel->chun_name;
$sebi_data->adm_phone = $channel->chun_phone;
$sebi_data->adm_address = $channel->chun_address;
}
$sell_data = DB::table('sell as s')
->leftJoin('admin as a', 's.sell_adm_id', '=', 'a.adm_id')
->where('sell_sebi_id',$request['sebi_id'])
->get(['sell_create_time', 'sell_number', 'sell_adm_id',
'sell_price', 'sell_actual_price', 'adm_name as sell_adm_name']);
$data['sebi_data'] = $sebi_data;
$data['sell_data'] = $sell_data;
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data]);
}
$user_info = Common::getUserInfo($request['api_token']);
DB::beginTransaction();
$update_data['sebi_state'] = $request['sebi_state'];
$update_data['sebi_audit_time'] = date('Y-m-d H:i:s'); //审核时间
$update_data['sebi_audit_adm_id'] = $user_info->adm_id; //审核人
$update_data['sebi_update_time'] = date('Y-m-d H:i:s');
$update_state = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->update($update_data);
// 获取客户单位名称
if($sebi_data->sebi_type == 1){
$client_name = '';
}else{
$client_name = DB::table('channel_unit')
->where('chun_id',$sebi_data->sebi_client_id)
->value('chun_unit_name');
}
//如果是同意状态
if($request['sebi_state'] == 1){
// 6. 生成应收账单
$createBill = ReceivableBill::create(
$user_info, //用户信息
6, //类型:1.销售订单 2.预收款 3.订单账单 4.工单账单 5.采购账单 6.销售账单
0, //应收账款id
$request['sebi_id'], //原始id(订单账单id)
$sebi_data->sebi_number, //应收账款单号/原始号(订单账单编号)
$sebi_data->sebi_type, //客户类型:1.门店零售 2.来往单位
$sebi_data->sebi_client_id, //会员id/来往单位id
$client_name, //来往单位名称
$sebi_data->sebi_bill_price, //结算金额
date('Y-m-d H:i:s'), //结款时间
0, //会计科目id
0, //实际金额
0, //抹零金额
1, //状态:1.未核销 2.已核销
2, //应收账单id是否是自己 1.不是 2.是
'', //备注
0, //已收金额
'', //截止时间
1,//金额正负1正 2负值
7,//显示类型:1订单收款 2受托代收(订单代收)3委托代收(工单代收)4工单费用(工单收款)5订单账单 6工单账单 7销售账单 8预收款 9销售出库单
1//是否合并代收:1是2否
);
//账单下所有的订单为不统计状态
$statistics_type_update = DB::table('receivable_credit')
->where('recr_belongs_id',$request['sebi_id'])
->where('recr_type',6)
->update(['recr_statistics_type'=>2,'recr_update_time'=>date('Y-m-d H:i:s')]);
}else{
$createBill = true;
$statistics_type_update = true;
}
if($update_state && $createBill && $statistics_type_update) {
Common::addLog($user_info, getRealIp($request), '销售账单','审核',$sebi_data->sebi_number.'审核成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'审核成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'审核失败']);
}
}
// 查看
public function lookInfo(Request $request)
{
// 验证数据
$verify_data = new VerifySellBillController;
$error_message = $verify_data->delValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$sebi_data = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->first(['sebi_number', 'sebi_state', 'sebi_start_time', 'sebi_end_time',
'sebi_create_time', 'sebi_create_adm_id', 'sebi_wor_amount', 'sebi_bill_price',
'sebi_client_id', 'sebi_type', 'sebi_goods_sum' ,'sebi_total_price',
'sebi_audit_time', 'sebi_audit_adm_id', 'sebi_payment_time', 'sebi_payee_id',
'sebi_payment_way', 'sebi_payment_way', 'sebi_actual_price', 'sebi_remark', 'sebi_img',
'sebi_collection_price','sebi_zero_price']);
if(empty($sebi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
// 获取到创建人姓名
$sebi_data->sebi_create_adm_name = DB::table('admin')
->where('adm_id',$sebi_data->sebi_create_adm_id)
->value('adm_name');
// 获取到审核人姓名
$sebi_data->sebi_audit_adm_name = DB::table('admin')
->where('adm_id',$sebi_data->sebi_audit_adm_id)
->value('adm_name');
// 获取到人姓名
$sebi_data->sebi_payee_name = DB::table('admin')
->where('adm_id',$sebi_data->sebi_payee_id)
->value('adm_name');
// 获取客户单位信息
if($sebi_data->sebi_type == 1){
// 会员
$member = DB::table('member')
->where('mem_id',$sebi_data->sebi_client_id)
->first(['mem_name','mem_phone','mem_address']);
$sebi_data->unit_name = '';
$sebi_data->adm_name = $member->mem_name;
$sebi_data->adm_phone = $member->mem_phone;
$sebi_data->adm_address = $member->mem_address;
}else{
// 客户单位
$channel = DB::table('channel_unit')
->where('chun_id',$sebi_data->sebi_client_id)
->first(['chun_unit_name','chun_name','chun_phone','chun_address']);
$sebi_data->unit_name = $channel->chun_unit_name;
$sebi_data->adm_name = $channel->chun_name;
$sebi_data->adm_phone = $channel->chun_phone;
$sebi_data->adm_address = $channel->chun_address;
}
return response()->json(['code'=> 200,'msg'=>'success','data'=>$sebi_data]);
}
// 删除(做成了真删)
public function del(Request $request)
{
// 验证数据
$verify_data = new VerifySellBillController;
$error_message = $verify_data->delValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$sebi_data = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->first(['sebi_number', 'sebi_state', 'sebi_type', 'sebi_client_id', 'sebi_bill_price']);
if(empty($sebi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($sebi_data->sebi_state != 4){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'已驳回的账单才可以删除']);
}
DB::beginTransaction();
// 1.删除账单表
$del_orbi = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->delete();
// 2.解除销售出库单与账单的绑定关系
$update_data['sell_sebi_id'] = 0;
$update_data['sell_update_time'] = date('Y-m-d H:i:s');
$update_state = DB::table('sell')
->where('sell_sebi_id',$request['sebi_id'])
->update($update_data);
// 应收账单表新增数据
// if($request['sebi_type'] == 2){
// $analyze = Common::updateAnalyze(
// $user_info, //用户信息
// $request['sebi_client_id'], //客户单位id
// 1, //单量
// $request['sebi_bill_price'] * 100, //应收账款结算金额
// 2 //类型1.编辑+ 2.编辑-
// );
// }else{
// $analyze = true;
// }
if($del_orbi && $update_state) {
$user_info = Common::getUserInfo($request['api_token']);
Common::addLog($user_info, getRealIp($request), '销售账单','删除',$sebi_data->sebi_number.'删除成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'删除成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'删除失败']);
}
}
// 反审核
public function cancelAudit(Request $request)
{
// 验证数据
$verify_data = new VerifySellBillController;
$error_message = $verify_data->delValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 验证当前账单是否存在
$sebi_data = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->first(['sebi_number', 'sebi_state']);
if(empty($sebi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($sebi_data->sebi_state != 4 && $sebi_data->sebi_state != 1){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'已驳回或者未结款的账单才可以反审核']);
}
$update_data['sebi_state'] = 3; // 账单状态1.未结款 2.已结款 3.待审核 4.已驳回 5.部分结款
$update_data['sebi_update_time'] = date('Y-m-d H:i:s');
DB::beginTransaction();
// 1.修改状态
$update_state = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->update($update_data);
//删除该账单
$del_credit = DB::table('receivable_credit')
->where('recr_cid',$user_info->adm_cid)
->where('recr_shop_superior_id',$shop_id)
->where('recr_type',6) //类型 6.销售账单
->where('recr_belongs_id',0) //所属账单id为0
->where('recr_original_id',$request['sebi_id']) //与类型所对应的id
->delete();
// 所属账单id改为0,统计状态为1
$update_belongs = DB::table('receivable_credit')
->where('recr_type',6) //类型 : 销售账单
->where('recr_belongs_id',$request['sebi_id'])
->update(['recr_belongs_id'=>0,'recr_update_time'=>date('Y-m-d H:i:s'),'recr_statistics_type'=>1]);
if($update_belongs || $update_belongs===0){
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'编辑失败']);
}
if($update_state && $del_credit) {
Common::addLog($user_info, getRealIp($request), '订单账单','反审核',$sebi_data->sebi_number.'反审核成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'反审核成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'反审核失败']);
}
}
// 编辑
public function edit(Request $request)
{
// 验证数据
$verify_data = new VerifySellBillController;
$error_message = $verify_data->editValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$user_info = Common::getUserInfo($request['api_token']);
$sebi_state = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->value('sebi_state');
if(($sebi_state == 2) || ($sebi_state == 5)){
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'该账单已结款']);
}
DB::beginTransaction();
// 1.解除该销售账单与原来销售出库单的绑定关系
$relieve_data['sell_sebi_id'] = 0; //账单id改为0
$relieve_data['sell_update_time'] = date('Y-m-d H:i:s');
$relieve_relation = DB::table('sell')
->where('sell_sebi_id',$request['sebi_id'])
->update($relieve_data);
$sell_price_data = DB::table('sell')
->whereIn('sell_id',$request['sell_id'])
->get(['sell_actual_price','sell_price']);
$sell_actual_price = 0;
$sell_price = 0;
foreach ($sell_price_data as $key => $value) {
$sell_actual_price += $value->sell_actual_price;//实际金额
$sell_price += $value->sell_price;//合计金额
}
// 2.重新绑定销售出库单与账单的关系
$sql = 'UPDATE `faster_sell` SET ';
$sell_sebi_id = ''; //账单id
$update_time = ''; //调货时间
$sell_id = "";
foreach ($request['sell_id'] as $key => $value) {
// 更改账单id
$sell_sebi_id = $sell_sebi_id . ' WHEN ' .$value;
$sell_sebi_id = $sell_sebi_id . ' THEN ' .$request['sebi_id'];
// 更改时间
$update_time = $update_time . ' WHEN ' .$value;
$update_time = $update_time . ' THEN "' .date('Y-m-d H:i:s').'"';
//要更改的销售单id
$sell_id = $sell_id . $value.',';
}
$sql = $sql .' `sell_sebi_id`= CASE `sell_id` '.$sell_sebi_id.' END,';
$sql = $sql .' `sell_update_time`= CASE `sell_id` '.$update_time.' END';
$sql = $sql .' WHERE `sell_id` IN ('.trim($sell_id,',').')';
$save_sell = DB::update($sql);
// 3.修改单量 改为待审核状态
$update_bill['sebi_wor_amount'] = count($request['sell_id']); //单量
$update_bill['sebi_state'] = 3; //3.待审核
$update_bill['sebi_update_time'] = date('Y-m-d H:i:s');
$update_bill['sebi_total_price'] = $sell_price;
$update_bill['sebi_bill_price'] = $sell_actual_price;
$bill_data = DB::table('sell_bill')
->where('sebi_id',$request['sebi_id'])
->update($update_bill);
//1.未结款
if($sebi_state == 1){
// print_sql();
// $credit_data = DB::table('receivable_credit')
// ->where('recr_belongs_id',$request['sebi_id'])
// ->update(['recr_belongs_id'=>0,'recr_update_time'=>date('Y-m-d H:i:s')]);
$credit_data = DB::update("update `faster_receivable_credit` set `recr_belongs_id` = 0, `recr_update_time` = '".date('Y-m-d H:i:s')."' where `recr_belongs_id` = ".$request['sebi_id']);
if($credit_data || $credit_data===0){
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'编辑失败']);
}
$del_data = DB::table('receivable_credit')
->where('recr_original_id',$request['sebi_id'])
->where('recr_type',6)
->delete();
}else{
$del_data = true;
}
if($relieve_relation && $save_sell && $bill_data && $del_data) {
Common::addLog($user_info, getRealIp($request), '销售账单','编辑',$request['sebi_number'].'编辑成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'编辑成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'编辑失败']);
}
}
}
<?php
namespace App\Http\Controllers\Api\AccountManage;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AccountManage\VerifyWorkBillController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
use App\Http\Models\Api\ReceivableBill;
use App\Http\Models\Api\AccountingSettlement;
use App\Http\Models\Api\AccountSubject;
class WorkBillController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyWorkBillController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('work_bill')
->where('wobi_cid', $user_info->adm_cid)
->where('wobi_superior_shop_id', $shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['wobi_state'])) {
$query->where('wobi_state', $search_data['wobi_state']);
}
}) //账单状态
->where(function($query) use($search_data) {
if (!empty($search_data['wobi_number'])) {
$query->where('wobi_number', 'like', $search_data['wobi_number'].'%' );
}
}) //账单编号
// ->where(function($query) use($search_data) {
// if (!empty($search_data['wobi_audit_adm_id'])) {
// $query->where('wobi_audit_adm_id', $search_data['wobi_audit_adm_id']);
// }
// }) //审核人id
// ->where(function($query) use($search_data) {
// if (!empty($search_data['wobi_payment_way'])) {
// $query->where('wobi_payment_way', $search_data['wobi_payment_way']);
// }
// }) //付款方式
// ->where(function($query) use($search_data) {
// if (!empty($search_data['wobi_payment_time'])) {
// $query->where('wobi_payment_time', 'like', $search_data['wobi_payment_time'].'%' );
// }
// }) //付款时间
// ->where(function($query) use($search_data) {
// if (!empty($search_data['wobi_payer'])) {
// $query->where('wobi_payer', 'like', $search_data['wobi_payer'].'%' );
// }
// }) //付款人
// ->where(function($query) use($search_data) {
// if (!empty($search_data['wobi_remark'])) {
// $query->where('wobi_remark', 'like', $search_data['wobi_remark'].'%' );
// }
// }) //备注
// ->where(function($query) use($search_data) {
// if (!empty($search_data['wobi_client_id'])) {
// $query->where('wobi_type', 2 )
// ->where('wobi_client_id', $search_data['wobi_client_id'] );
// }
// }) //客户单位
->select('wobi_id', 'wobi_number', 'wobi_start_time', 'wobi_end_time', 'wobi_number',
'wobi_bill_price', 'wobi_payment_time', 'wobi_payment_way',
'wobi_actual_price', 'wobi_state', 'wobi_audit_time', 'wobi_audit_adm_id',
'wobi_create_adm_id', 'wobi_remark','wobi_wor_amount', 'wobi_client_id', 'wobi_type')
->orderBy('wobi_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
$mem_id = [];
$channel_id = [];
$league_id = [];
foreach ($list_items as $key => $value) {
$adm_id[] = $value->wobi_create_adm_id;
$adm_id[] = $value->wobi_audit_adm_id;
if ($value->wobi_type == 1){
// 会员
$mem_id[] = $value->wobi_client_id;
} elseif ($value->wobi_type == 2){
// 客户单位
$channel_id[] = $value->wobi_client_id;
} else {
// 加盟店
$league_id[] = $value->wobi_client_id;
}
}
$adm_id = array_unique($adm_id);
$mem_id = array_unique($mem_id);
$channel_id = array_unique($channel_id);
$league_id = array_unique($league_id);
// 查找账号id对应的账号姓名
$find_admin = DB::table('admin')
->whereIn('adm_id', $adm_id)
->get(['adm_id', 'adm_name']);
// 查找所对应的 会员信息
$find_mem = DB::table('member')
->whereIn('mem_id', $mem_id)
->get(['mem_id','mem_name','mem_phone','mem_address']);
// 查找所对应的 客户单位信息
$find_channel = DB::table('channel_unit')
->whereIn('chun_id', $channel_id)
->get(['chun_id','chun_unit_name','chun_name','chun_phone','chun_address']);
// 查找所对应的 门店信息
$find_shop = DB::table('shop')
->whereIn('shop_id', $league_id)
->get(['shop_id','shop_store_name','shop_name','shop_phone','shop_address']);
}else{
$find_admin = [];
$find_mem = [];
$find_channel = [];
$find_shop = [];
}
$state_count = DB::table('work_bill')
->where('wobi_cid', $user_info->adm_cid)
->where('wobi_superior_shop_id', $shop_id)
->select(DB::raw('count(*) as count, wobi_state'))
->groupBy('wobi_state')
->get();
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['find_admin'] = $find_admin; //返回数据
$data_info['state_count'] = $state_count; //返回数据
$data_info['find_mem'] = $find_mem; //会员信息
$data_info['find_channel'] = $find_channel; //客户单位信息
$data_info['find_shop'] = $find_shop; //加盟店信息
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 详情
public function billNumber(Request $request)
{
// 验证数据
$verify_data = new VerifyWorkBillController;
$error_message = $verify_data->billNumberValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
if($request['type'] == 1){
// 账单信息
$bill = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->first(['wobi_id','wobi_number','wobi_start_time','wobi_end_time','wobi_create_time','wobi_create_adm_id',
'wobi_wor_amount','wobi_bill_price','wobi_actual_price','wobi_type','wobi_client_id']);
if($bill) {
if($bill->wobi_type == 2){
// 来往单位
$bill->wobi_client_name = DB::table('channel_unit')
->where('chun_id',$bill->wobi_client_id)
->value('chun_unit_name');
}elseif($bill->wobi_type == 1){
// 客户名称
$bill->wobi_client_name = DB::table('admin')
->where('adm_id',$bill->wobi_client_id)
->value('adm_name');
}else{
// 加盟店名称
$bill->wobi_client_name = DB::table('shop')
->where('shop_id',$bill->wobi_client_id)
->value('shop_store_name');
}
return response()->json(['code'=> 200,'msg'=>'success','data'=>$bill]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}else{
$list_data = DB::table('work_order as a')
->leftJoin('work_client as b', 'b.wocl_wor_id', '=', 'a.wor_id')
->where('wor_cid', $user_info->adm_cid)
->where('wor_superior_shop_id', $shop_id)
->where('wor_wobi_id', $request['wobi_id'])
->where(function($query) use($search_data) {
if (!empty($search_data['wor_order_number'])) {
$query->where('wor_order_number', 'like', $search_data['wor_order_number'].'%' );
}
}) //工单编号
->where(function($query) use($search_data) {
if (!empty($search_data['wocl_name'])) {
$query->where('wocl_name', 'like', '%'.$search_data['wocl_name'].'%' );
}
}) //客户姓名
->where(function($query) use($search_data) {
if (!empty($search_data['wocl_phone'])) {
$query->where('wocl_phone', 'like', '%'.$search_data['wocl_phone'].'%' );
}
}) //客户电话
->where(function($query) use($search_data) {
if (!empty($search_data['wocl_address'])) {
$query->where('wocl_address', 'like', $search_data['wocl_address'].'%' );
}
}) //地址
->select('wor_id', 'wor_create_id', 'wor_number', 'wor_order_number', 'wor_service_sepr_id',
'wor_service_adm_id', 'wor_service_type', 'wor_service_state', 'wor_state',
'wor_pass', 'wor_type', 'wor_goo_amount', 'wor_remark', 'wor_create_time',
'wocl_channel_unit', 'wocl_name', 'wocl_phone', 'wocl_car_num', 'wocl_address','wor_shop_id','wor_service_shop_id','wor_ware_id', 'wor_collection_price', 'wocl_longitude',
'wocl_latitude','wor_orla_id')
->orderBy('wor_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if(empty($list_items)){
$wor_id = [];
$adm_id = [];
$service_sepr_id = [];
$find_admin = [];
$work_goods = [];
$service_project = [];
$find_shop = [];
$work_log = [];
$recycle_price = 0;
$order_label = [];
$shop_ids = [];
$wor_orla_id= [];
}else{
// 查找工单商品
foreach ($list_items as $key => $value) {
$wor_id[] = $value->wor_id;
$adm_id[] = $value->wor_create_id;
$adm_id[] = $value->wor_service_adm_id;
$service_sepr_id[] = $value->wor_service_sepr_id;
$shop_ids[] = $value->wor_shop_id;
$shop_ids[] = $value->wor_service_shop_id;
$wor_orla_id[] = $value->wor_orla_id; //订单标签id
}
}
$adm_id = array_unique($adm_id);
// 查找账号id对应的账号姓名
$find_admin = DB::table('admin')
->whereIn('adm_id', $adm_id)
->get(['adm_id', 'adm_name']);
// 查找工单商品
$work_goods = DB::table('work_good')
->whereIn('wogo_wor_id',$wor_id)
->get(['wogo_wor_id','wogo_goo_id','wogo_goo_name','wogo_goo_goods_encode',
'wogo_goo_price','wogo_goo_amount','wogo_is_recycle',
'wogo_actual_recycle_number','wogo_remark','wogo_collection_price','wogo_state']);
// 查找账号id对应的账号姓名
$find_shop = DB::table('shop')
->whereIn('shop_id', $shop_ids)
->get(['shop_id', 'shop_store_name']);
// 查找所有订单回收金额
$recycle_price = DB::table('junk_recycle')
->whereIn('jur_wor_id',$wor_id)
->where('jur_price', '!=', 0)
->get(['jur_wor_id','jur_price']);
// 查找操作记录
$work_log = DB::table('order_log')
->whereIn('orlo_wor_id',$wor_id)
->get(['orlo_wor_id','orlo_time','orlo_create_adm_name','orlo_content']);
// // 查找订单标签
// $order_label = DB::table('order_label')
// ->whereIn('orla_id',$wor_orla_id)
// ->get(['orla_id','orla_name']);
// 服务项目
$service_project = DB::table('service_project')
->whereIn('sepr_id', $service_sepr_id)
->get(['sepr_id', 'sepr_name']);
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['find_admin'] = $find_admin; //返回账号姓名
$data_info['work_goods'] = $work_goods; //订单商品数据
$data_info['service_project'] = $service_project; //服务项目
$data_info['find_shop'] = $find_shop; //返回门店名称
$data_info['work_log'] = $work_log; //操作记录
$data_info['recycle_price'] = $recycle_price; //订单回收金额
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
}
// 结款
public function settleAccounts(Request $request)
{
// 验证数据
$verify_data = new VerifyWorkBillController;
$error_message = $verify_data->getInfoValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$wobi_data = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->first(['wobi_number', 'wobi_state', 'wobi_start_time', 'wobi_end_time',
'wobi_create_time', 'wobi_create_adm_id', 'wobi_wor_amount', 'wobi_bill_price',
'wobi_client_id', 'wobi_type', 'wobi_goods_sum','wobi_total_price',
'wobi_collection_price','wobi_receive_price','wobi_img']);
if(empty($wobi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($request['type'] == 1){
// 获取到创建人姓名
$wobi_data->wobi_create_adm_name = DB::table('admin')
->where('adm_id',$wobi_data->wobi_create_adm_id)
->value('adm_name');
// 获取客户单位信息
if($wobi_data->wobi_type == 1){
// 会员
$member = DB::table('member')
->where('mem_id',$wobi_data->wobi_client_id)
->first(['mem_name','mem_phone','mem_address']);
$wobi_data->unit_name = '';
$wobi_data->adm_name = $member->mem_name;
$wobi_data->adm_phone = $member->mem_phone;
$wobi_data->adm_address = $member->mem_address;
}else if($wobi_data->wobi_type == 2) {
// 客户单位
$channel = DB::table('channel_unit')
->where('chun_id',$wobi_data->wobi_client_id)
->first(['chun_unit_name','chun_name','chun_phone','chun_address']);
$wobi_data->unit_name = $channel->chun_unit_name;
$wobi_data->adm_name = $channel->chun_name;
$wobi_data->adm_phone = $channel->chun_phone;
$wobi_data->adm_address = $channel->chun_address;
} else {
// 加盟店
$shops = DB::table('shop')
->where('shop_id',$wobi_data->wobi_client_id)
->first(['shop_store_name','shop_name','shop_phone','shop_address']);
$wobi_data->unit_name = $shops->shop_store_name;
$wobi_data->adm_name = $shops->shop_name;
$wobi_data->adm_phone = $shops->shop_phone;
$wobi_data->adm_address = $shops->shop_address;
}
return response()->json(['code'=> 200,'msg'=>'success','data'=>$wobi_data]);
}
// 验证数据
$verify_data = new VerifyWorkBillController;
$error_message = $verify_data->settleAccountsValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$wobi_actual_price = $request['wobi_actual_price'] * 100; //实收金额
$zero_price = $request['zero_price'] ? $request['zero_price']*100 : 0; //抹零金额
// 还应收金额
$surplus_price = $wobi_data->wobi_bill_price-$wobi_data->wobi_receive_price;
if($wobi_actual_price > $surplus_price){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'实收金额不得大于还应收金额']);
}
$few = 0;
$img = '';
foreach ($request['wobi_img'] as $key => $value) {
// 调用全局函数 上传图片
$img .= uploadBase64Img($value).',';
$few++;
}
if($few == 0){
return response()->json(['code'=> 500, 'msg'=>'最少上传一张图片', 'data'=>'{}']);
}
if($few > 6){
return response()->json(['code'=> 500, 'msg'=>'最多上传六张图片', 'data'=>'{}']);
}
$img = $wobi_data->wobi_img.','.$img;
$img = trim($img, ',');
$user_info = Common::getUserInfo($request['api_token']);
// 获取来往单位名称
if($request['wobi_type'] == 1){
$client_name = '';
} else if($request['wobi_type'] == 2) {
$client_name = DB::table('channel_unit')
->where('chun_id',$request['wobi_client_id'])
->value('chun_unit_name');
} else if ($request['wobi_type'] == 3) {
$client_name = DB::table('shop')
->where('shop_id',$request['wobi_client_id'])
->value('shop_store_name');
}
// 查询出应收账款id
$recr_number_id = DB::table('receivable_credit')
->where('recr_type',4)
->where('recr_original_id',$request['wobi_id'])
->value('recr_number_id');
// 查询出是否应该为已核销
if($request['wobi_payment_type'] == 1){ //抹零
// 抹零金额+实收金额不得大于结算金额 等于结算金额改为已核销
if($wobi_actual_price + $zero_price < $surplus_price){
$check = 1; //未核销
}else{
$check = 2; //已核销
}
}else{ //分期结款 或者 预收款抵账
if($wobi_actual_price < $surplus_price){
$check = 1; //未核销
}else{
$check = 2; //已核销
}
}
DB::beginTransaction();
if($check == 2){
// 已核销 将所有应收账款与本账单有关的都改为已核销
// $update_state['recr_state'] = 2;
// $update_state['recr_update_time'] = date('Y-m-d H:i:s');
// $rece_data = DB::table('receivable_credit')
// ->where('recr_number_id',$recr_number_id)
// ->update($update_state);
// 查询出是否有包含本账单已经完结的预收款 改为已核销
// $recr_id = DB::table('receivable_credit')
// ->where('recr_type',2)
// ->where('recr_actual_price',0)
// ->get(['recr_id']);
// $recr_id = json_decode(json_encode($recr_id),true);
// $recr_id = array_column($recr_id,'recr_id');
// if(!empty($recr_id)){
// $state_data['recr_state'] = 2;
// $state_data['recr_update_time'] = date('Y-m-d H:i:s');
// $recr_state = DB::table('receivable_credit')
// ->whereIn('recr_id',$recr_id)
// ->update($state_data);
// }else{
// $recr_state = true;
// }
$wobi_state = 2; //2.已结款
}else{
// 未核销
// $rece_data = true;
// $recr_state = true;
$wobi_state = 5; //5.部分结款
}
// 修改工单账单表
$update_bill = DB::update('UPDATE `faster_work_bill` SET `wobi_receive_price`=`wobi_receive_price`+'.$wobi_actual_price.' ,`wobi_zero_price`=`wobi_zero_price`+'.$zero_price.',`wobi_actual_price`=`wobi_actual_price`+'.$wobi_actual_price.' ,`wobi_remark`= "'.$request['wobi_remark'].'" ,`wobi_payment_way`= '.$request['wobi_payment_way'].' ,`wobi_payee_id`= '.$user_info->adm_id.' ,`wobi_state`= '.$wobi_state.' ,`wobi_img`= "'.$img.'" ,`wobi_payment_time`= "'.date('Y-m-d H:i:s').'" ,`wobi_update_time`= "'.date('Y-m-d H:i:s').'" WHERE `wobi_id`=?',[$request['wobi_id']] );
// 6. 生成应收账单(记录)
$createBill = ReceivableBill::add(
$user_info, //用户信息
4, //类型:1.销售订单 2.预收款 3.订单账单 4.工单账单 5.采购账单 6.销售账单
$recr_number_id, //应收账款id
$request['wobi_id'], //原始id(账单id)
$wobi_data->wobi_number, //应收账款单号/原始号(账单编号)
$wobi_data->wobi_type, //客户类型:1.门店零售 2.来往单位
$wobi_data->wobi_client_id, //会员id/来往单位id
$client_name, //来往单位名称
$wobi_data->wobi_bill_price, //结算金额
date('Y-m-d H:i:s'), //结款时间
$request['acti_id'], //会计科目id
$wobi_actual_price, //实际金额
$zero_price, //抹零金额
$check, //状态:1.未核销 2.已核销
1, //应收账单id是否是自己 1.不是 2.是
$request['wobi_remark'] ? $request['wobi_remark'] : '', //备注
$wobi_data->wobi_receive_price + $wobi_actual_price, //已收金额
'' //截止时间
);
// 预收款抵账(减预收款金额)
if($request['wobi_payment_type'] == 3){
// 实收金额
$subtract = DB::table('receivable_credit')
->where('recr_id',$request['recr_id'])
->decrement('recr_actual_price',$wobi_actual_price);
$add_data['rede_advance_id'] = $request['recr_id']; //预付款id
$add_data['rede_recr_id'] = $createBill; //账单id
$details_data = DB::table('receivable_details')->insert($add_data);
// $AccountSubject = true;
}else{
$subtract = true;
$details_data = true;
// // 编辑科目管理表
// $AccountSubject = AccountSubject::Subject(
// $user_info, // [用户信息]
// 1, // [类型:1借2贷]
// $wobi_actual_price, // [金额]
// $request['acti_id'] // [科目id]
// );
}
// $acti_closing_account = DB::table('account_title')
// ->where('acti_id',$request['acti_id'])
// ->value('acti_closing_account');
// if($wobi_actual_price > $acti_closing_account){
// DB::rollBack();
// return response()->json(["code"=>500,'msg'=>'error','data'=>'科目余额不足']);
// }
// 添加结款明细
$AccountingSettlement = AccountingSettlement::add(
$user_info, // [用户信息]
3, // [单据类型1订单2订单账单3工单账单4采购账单5销售账单6预收款]
$request['wobi_id'], // [与单据类型对应的id]
$wobi_data->wobi_number, // [与单据类型对应的单号]
$wobi_data->wobi_type, // [买家类型1门店零售2来往单位]
$wobi_data->wobi_client_id, // [会员/客户id]
$client_name, // [来往单位名称]
$request['acti_id'], // [会计科目id]
1, // [类型1收入2支出]
$wobi_actual_price, // [实际金额](此次的实收金额)
$surplus_price, // [合计金额](此次的应收金额)
$surplus_price-$wobi_actual_price-$zero_price, // [欠收金额](此次结款后还应收金额)
$zero_price, // [抹零金额]
$request['wobi_remark'] ? $request['wobi_remark'] : '' // [备注]
);
// 应收账单表新增数据
// if($wobi_data->wobi_type == 2){
// $analyze = Common::updateAnalyze(
// $user_info, //用户信息
// $wobi_data->wobi_client_id, //客户单位id
// 1, //单量
// $wobi_data->wobi_bill_price, //应收账款结算金额
// 2 //类型1.编辑+ 2.编辑-
// );
// }else{
// $analyze = true;
// }
if(/*$rece_data && $recr_state && */$update_bill && $createBill && $AccountingSettlement && $subtract && $details_data) {
Common::addLog($user_info, getRealIp($request), '工单账单','结款',$wobi_data->wobi_number.'结款成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'结款成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'结款失败']);
}
}
// 查看
public function lookInfo(Request $request)
{
// 验证数据
$verify_data = new VerifyWorkBillController;
$error_message = $verify_data->delValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$wobi_data = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->first(['wobi_number', 'wobi_state', 'wobi_start_time', 'wobi_end_time',
'wobi_create_time', 'wobi_create_adm_id', 'wobi_wor_amount', 'wobi_bill_price',
'wobi_client_id', 'wobi_type', 'wobi_goods_sum', 'wobi_payment_way',
'wobi_total_price', 'wobi_audit_time', 'wobi_audit_adm_id', 'wobi_payment_time',
'wobi_payee_id', 'wobi_actual_price', 'wobi_remark', 'wobi_img']);
if(empty($wobi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
// 获取到创建人姓名
$wobi_data->wobi_create_adm_name = DB::table('admin')
->where('adm_id',$wobi_data->wobi_create_adm_id)
->value('adm_name');
// 获取到审核人姓名
$wobi_data->wobi_audit_adm_name = DB::table('admin')
->where('adm_id',$wobi_data->wobi_audit_adm_id)
->value('adm_name');
// 获取到结款人姓名
$wobi_data->wobi_payee_name = DB::table('admin')
->where('adm_id',$wobi_data->wobi_payee_id)
->value('adm_name');
// 获取客户单位信息
if($wobi_data->wobi_type == 1){
// 会员
$member = DB::table('member')
->where('mem_id',$wobi_data->wobi_client_id)
->first(['mem_name','mem_phone','mem_address']);
$wobi_data->unit_name = '';
$wobi_data->adm_name = $member->mem_name;
$wobi_data->adm_phone = $member->mem_phone;
$wobi_data->adm_address = $member->mem_address;
} else if($wobi_data->wobi_type == 2) {
// 客户单位
$channel = DB::table('channel_unit')
->where('chun_id',$wobi_data->wobi_client_id)
->first(['chun_unit_name','chun_name','chun_phone','chun_address']);
$wobi_data->unit_name = $channel->chun_unit_name;
$wobi_data->adm_name = $channel->chun_name;
$wobi_data->adm_phone = $channel->chun_phone;
$wobi_data->adm_address = $channel->chun_address;
} else if ($wobi_data->wobi_type == 3) {
// 加盟店
$shop = DB::table('shop')
->where('shop_id',$wobi_data->wobi_client_id)
->first(['shop_store_name','shop_name','shop_phone','shop_address']);
$wobi_data->unit_name = $shop->shop_store_name;
$wobi_data->adm_name = $shop->shop_name;
$wobi_data->adm_phone = $shop->shop_phone;
$wobi_data->adm_address = $shop->shop_address;
}
return response()->json(['code'=> 200,'msg'=>'success','data'=>$wobi_data]);
}
// 审核
public function audit(Request $request)
{
// 验证数据
$verify_data = new VerifyWorkBillController;
$error_message = $verify_data->auditValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$wobi_data = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->first(['wobi_number', 'wobi_state', 'wobi_start_time', 'wobi_end_time',
'wobi_create_time', 'wobi_create_adm_id', 'wobi_wor_amount', 'wobi_bill_price',
'wobi_client_id', 'wobi_type', 'wobi_goods_sum']);
if(empty($wobi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($wobi_data->wobi_state != 3){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'待审核状态下才可以审核']);
}
if($request['type'] == 1){
// 获取到创建人姓名
$wobi_data->wobi_create_adm_name = DB::table('admin')
->where('adm_id',$wobi_data->wobi_create_adm_id)
->value('adm_name');
// 获取客户单位信息
if($wobi_data->wobi_type == 1){
// 会员
$member = DB::table('member')
->where('mem_id',$wobi_data->wobi_client_id)
->first(['mem_name','mem_phone','mem_address']);
$wobi_data->unit_name = '';
$wobi_data->adm_name = $member->mem_name;
$wobi_data->adm_phone = $member->mem_phone;
$wobi_data->adm_address = $member->mem_address;
} elseif ($wobi_data->wobi_type == 2){
// 客户单位
$channel = DB::table('channel_unit')
->where('chun_id',$wobi_data->wobi_client_id)
->first(['chun_unit_name','chun_name','chun_phone','chun_address']);
$wobi_data->unit_name = $channel->chun_unit_name;
$wobi_data->adm_name = $channel->chun_name;
$wobi_data->adm_phone = $channel->chun_phone;
$wobi_data->adm_address = $channel->chun_address;
}else{
// 加盟店
$shop = DB::table('shop')
->where('shop_id',$wobi_data->wobi_client_id)
->first(['shop_store_name','shop_name','shop_phone','shop_address']);
$wobi_data->unit_name = $shop->shop_store_name;
$wobi_data->adm_name = $shop->shop_name;
$wobi_data->adm_phone = $shop->shop_phone;
$wobi_data->adm_address = $shop->shop_address;
}
$work_order = DB::table('work_order as w')
->leftJoin('order as o', 'w.wor_order_id', '=', 'o.ord_id')
->leftJoin('admin as a', 'w.wor_create_id', '=', 'a.adm_id')
->where('wor_wobi_id',$request['wobi_id'])
->get(['wor_achieve_time', 'wor_number', 'wor_create_id',
'wor_actual_price', 'ord_state', 'adm_name as wor_create_name']);
$data['wobi_data'] = $wobi_data;
$data['work_order'] = $work_order;
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data]);
}
$user_info = Common::getUserInfo($request['api_token']);
DB::beginTransaction();
$update_data['wobi_state'] = $request['wobi_state'];
$update_data['wobi_audit_time'] = date('Y-m-d H:i:s'); //审核时间
$update_data['wobi_audit_adm_id'] = $user_info->adm_id; //审核人
$update_data['wobi_update_time'] = date('Y-m-d H:i:s');
$update_state = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->update($update_data);
// 获取客户单位名称/加盟店名称
if($wobi_data->wobi_type == 1){
// 会员
$client_name = '';
} elseif ($wobi_data->wobi_type == 2){
$client_name = DB::table('channel_unit')
->where('chun_id',$wobi_data->wobi_client_id)
->value('chun_unit_name');
} else {
$client_name = DB::table('shop')
->where('shop_id',$wobi_data->wobi_client_id)
->value('shop_store_name');
}
//如果是同意状态
if($request['wobi_state'] == 1){
// 6. 生成应收账单
$createBill = ReceivableBill::add(
$user_info, //用户信息
4, //类型:1.销售订单 2.预收款 3.订单账单 4.工单账单 5.采购账单 6.销售账单
0, //应收账款id
$request['wobi_id'], //原始id(订单账单id)
$wobi_data->wobi_number, //应收账款单号/原始号(订单账单编号)
$wobi_data->wobi_type, //客户类型:1.门店零售 2.来往单位
$wobi_data->wobi_client_id, //会员id/来往单位id
$client_name, //来往单位名称/门店名称
$wobi_data->wobi_bill_price, //结算金额
date('Y-m-d H:i:s'), //结款时间
0, //会计科目id
0, //实际金额
0, //抹零金额
1, //状态:1.未核销 2.已核销
2, //应收账单id是否是自己 1.不是 2.是
'', //备注
0, //已收金额
'' //截止时间
);
}else{
$createBill = true;
}
if($update_state && $createBill) {
Common::addLog($user_info, getRealIp($request), '工单账单','审核',$wobi_data->wobi_number.'审核成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'审核成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'审核失败']);
}
}
// 删除(做成了真删)
public function del(Request $request)
{
// 验证数据
$verify_data = new VerifyWorkBillController;
$error_message = $verify_data->delValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 验证当前账单是否存在
$wobi_data = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->first(['wobi_number', 'wobi_state', 'wobi_type', 'wobi_client_id', 'wobi_bill_price']);
if(empty($wobi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($wobi_data->wobi_state != 4){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'已驳回的账单才可以删除']);
}
DB::beginTransaction();
// 1.删除账单表
$del_orbi = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->delete();
// 2.解除工单与账单的绑定关系
$update_data['wor_wobi_id'] = 0;
$update_data['wor_update_time'] = date('Y-m-d H:i:s');
$update_state = DB::table('work_order')
->where('wor_wobi_id',$request['wobi_id'])
->update($update_data);
// 3.应收账单表新增数据
// if($request['wobi_type'] == 2){
// $analyze = Common::updateAnalyze(
// $user_info, //用户信息
// $request['wobi_client_id'], //客户单位id
// 1, //单量
// $request['wobi_bill_price'] * 100, //应收账款结算金额
// 2 //类型1.编辑+ 2.编辑-
// );
// }else{
// $analyze = true;
// }
if($del_orbi && $update_state) {
$user_info = Common::getUserInfo($request['api_token']);
Common::addLog($user_info, getRealIp($request), '工单账单','删除',$wobi_data->wobi_number.'删除成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'删除成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'删除失败']);
}
}
// 反审核
public function cancelAudit(Request $request)
{
// 验证数据
$verify_data = new VerifyWorkBillController;
$error_message = $verify_data->delValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$user_info = Common::getUserInfo($request['api_token']);
// 验证当前账单是否存在
$wobi_data = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->first(['wobi_number', 'wobi_state']);
if(empty($wobi_data)){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'当前账单不存在']);
}
if($wobi_data->wobi_state != 4 && $wobi_data->wobi_state != 1){
return response()->json(['code'=> 500,'msg'=>'error','data'=>'已驳回或者未结款的账单才可以反审核']);
}
$update_data['wobi_state'] = 3; // 账单状态1.未结款 2.已结款 3.待审核 4.已驳回 5.部分结款
$update_data['wobi_update_time'] = date('Y-m-d H:i:s');
DB::beginTransaction();
// 1.修改状态
$update_state = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->update($update_data);
// 通过的账单 删除应收账款
if($wobi_data->wobi_state == 5){
$del_credit = DB::table('receivable_credit')
->where('recr_type',4) //类型 4.工单账单
->where('recr_original_id',$request['wobi_id']) //与类型所对应的id
->delete();
}else{
$del_credit = true;
}
if($update_state && $del_credit) {
Common::addLog($user_info, getRealIp($request), '工单账单','反审核',$wobi_data->wobi_number.'反审核成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'反审核成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'反审核失败']);
}
}
// 编辑
public function edit(Request $request)
{
// 验证数据
$verify_data = new VerifyWorkBillController;
$error_message = $verify_data->editValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$user_info = Common::getUserInfo($request['api_token']);
// 1.解除该工单账单与原来工单的绑定关系
$relieve_data['wor_wobi_id'] = 0; //账单id改为0
$relieve_data['wor_update_time'] = date('Y-m-d H:i:s');
$relieve_relation = DB::table('work_order')
->where('wor_wobi_id',$request['wobi_id'])
->update($relieve_data);
// 2.重新绑定工单与账单的关系
$sql = 'UPDATE `faster_work_order` SET ';
$wor_wobi_id = ''; //账单id
$update_time = ''; //调货时间
$wor_id = "";
foreach ($request['wor_id'] as $key => $value) {
// 更改账单id
$wor_wobi_id = $wor_wobi_id . ' WHEN ' .$value;
$wor_wobi_id = $wor_wobi_id . ' THEN ' .$request['wobi_id'];
// 更改时间
$update_time = $update_time . ' WHEN ' .$value;
$update_time = $update_time . ' THEN "' .date('Y-m-d H:i:s').'"';
//要更改的工单id
$wor_id = $wor_id . $value.',';
}
$sql = $sql .' `wor_wobi_id`= CASE `wor_id` '.$wor_wobi_id.' END,';
$sql = $sql .' `wor_update_time`= CASE `wor_id` '.$update_time.' END';
$sql = $sql .' WHERE `wor_id` IN ('.trim($wor_id,',').')';
$save_work = DB::update($sql);
// 3.修改单量 改为待审核状态
$update_bill['wobi_wor_amount'] = count($request['wor_id']); //单量
$update_bill['wobi_state'] = 3; //3.待审核
$update_bill['wobi_update_time'] = date('Y-m-d H:i:s');
$bill_data = DB::table('work_bill')
->where('wobi_id',$request['wobi_id'])
->update($update_bill);
if($relieve_relation && $save_work && $bill_data) {
Common::addLog($user_info, getRealIp($request), '工单账单','编辑',$request['wobi_number'].'编辑成功');
DB::commit();
return response()->json(['code'=> 200,'msg'=>'success','data'=>'编辑成功']);
}else{
DB::rollBack();
return response()->json(['code'=> 500,'msg'=>'error','data'=>'编辑失败']);
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
namespace App\Http\Controllers\Api\AfterSaleManage;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AfterSaleManage\VerifyAfterLabelController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
class AfterLabelController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyAfterLabelController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$page_size = $request->input('show_count', 10);
$search_data = $request->all();
$list_data = DB::table('after_label as afla')
->leftJoin('after_label as aflb', 'afla.afla_parent_id', '=', 'aflb.afla_id')
->where('afla.afla_cid', $user_info->adm_cid)
->where('afla.afla_superior_shop_id', $shop_id)
->where('afla.afla_delete', 1)
->where(function ($query) use ($search_data) {
if (!empty($search_data['afla_name'])) {
$query->where('afla.afla_name', 'like', '%' . $search_data['afla_name'].'%');
}
})
->where(function ($query) use ($search_data) {
if (!empty($search_data['afla_state'])) {
$query->where('afla.afla_state', $search_data['afla_state']);
}
})
->select('afla.afla_id', 'afla.afla_name', 'afla.afla_state', 'afla.afla_parent_id', 'aflb.afla_name as afla_parent_name')
->orderBy('afla.afla_id', 'desc')
->paginate($page_size);
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $page_size; //一页显示多少个
$data_info['data'] = $list_data->items(); //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if ($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
} else {
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 新增
public function add(Request $request)
{
// 验证数据
$verify_data = new VerifyAfterLabelController;
$error_message = $verify_data->addValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 1. 判断售后标签名称是否存在
$find_afla_name = DB::table('after_label')
->where('afla_delete', 1)
->where('afla_cid', $user_info->adm_cid)
->where('afla_superior_shop_id', $shop_id)
->where('afla_name', $request['afla_name'])
->select('afla_id')
->first();
if ($find_afla_name) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'售后标签名称已存在']);
}
$afla_data['afla_cid'] = $user_info->adm_cid;
$afla_data['afla_superior_shop_id'] = $shop_id;
$afla_data['afla_shop_id'] = $user_info->adm_shop_id;
$afla_data['afla_name'] = $request['afla_name'];
$afla_data['afla_parent_id'] = $request['afla_parent_id'];
// 判断隶属上级
if ($request['afla_parent_id']) {
// 查找隶属品类是第几级
$afla_rank = DB::table('after_label')
->where('afla_id', $request['afla_parent_id'])
->value('afla_rank');
if ($afla_rank >= '3') {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'所属售后标签已超过三级']);
}
$afla_data['afla_rank'] = $afla_rank + 1;
} else {
$afla_data['afla_rank'] = 1;
}
// 新增售后标签
$afla_res = DB::table('after_label')->insert($afla_data);
if ($afla_res) {
Common::addLog($user_info, getRealIp($request), '售后标签', '新增', '新增售后标签:'.$request['afla_name'].'成功');
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'新增售后标签成功']);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'新增售后标签失败']);
}
}
// 编辑
public function edit(Request $request)
{
// 验证数据
$verify_data = new VerifyAfterLabelController;
$error_message = $verify_data->editValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 判断售后标签名称是否存在
$find_afla_name = DB::table('after_label')
->where('afla_id', '<>', $request['afla_id'])
->where('afla_delete', 1)
->where('afla_cid', $user_info->adm_cid)
->where('afla_superior_shop_id', $shop_id)
->where('afla_name', $request['afla_name'])
->select('afla_id')
->first();
if ($find_afla_name) {
return response()->json(['code'=>500,'msg'=>'error','data'=>'标签已存在']);
}
$afla_data['afla_name'] = $request['afla_name'];
$afla_data['afla_parent_id'] = $request['afla_parent_id'];
$afla_data['afla_update_time'] = date('Y-m-d H:i:s');
if ($request['cate_parent_id']) {
// 查询隶属售后标签是第几级
$afla_rank = DB::table('after_label')
->where('afla_id', $request['afla_parent_id'])
->value('afla_rank');
if ($afla_rank >= '3') {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'所属售后标签已超过三级']);
}
$afla_data['afla_rank'] = $afla_rank + 1;
} else {
$afla_data['afla_rank'] = 1;
}
$afla_res = DB::table('after_label')
->where('afla_id', $request['afla_id'])
->update($afla_data);
if ($afla_res) {
Common::addLog($user_info, getRealIp($request), '售后标签', '编辑', '编辑售后标签:'.$request['afla_name'].'成功');
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'编辑售后标签:成功']);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'编辑售后标签:失败']);
}
}
// 启用
public function start(Request $request)
{
// 验证数据
$verify_data = new VerifyAfterLabelController;
$error_message = $verify_data->startValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 启用
$update_data['afla_state'] = 1;//状态1启用2停用
$update_data['afla_update_time'] = date('Y-m-d H:i:s');
$afla_res = DB::table('after_label')
->whereIn('afla_id', $request['afla_id'])
->update($update_data);
if ($afla_res) {
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 查询信息
$find_afla_name = DB::table('after_label')
->whereIn('afla_id', $request['afla_id'])
->select('afla_name')
->get();
foreach ($find_afla_name as $key => $value) {
$afla_name[] = $value->afla_name;
}
Common::addLog($user_info, getRealIp($request), '售后标签', '启用', '售后标签:('.implode(',', $afla_name).')启用成功');
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'启用成功']);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'启用失败']);
}
}
// 停用
public function stop(Request $request)
{
// 验证数据
$verify_data = new VerifyAfterLabelController;
$error_message = $verify_data->startValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 停用
$update_data['afla_state'] = 2;//状态1启用2停用
$update_data['afla_update_time'] = date('Y-m-d H:i:s');
$afla_res = DB::table('after_label')
->whereIn('afla_id', $request['afla_id'])
->update($update_data);
if ($afla_res) {
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 查询信息
$find_afla_name = DB::table('after_label')
->whereIn('afla_id', $request['afla_id'])
->select('afla_name')
->get();
foreach ($find_afla_name as $key => $value) {
$afla_name[] = $value->afla_name;
}
Common::addLog($user_info, getRealIp($request), '售后标签', '停用', '售后标签:('.implode(',', $afla_name).')停用成功');
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'停用成功']);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'停用失败']);
}
}
// 删除
public function delete(Request $request)
{
// 验证数据
$verify_data = new VerifyAfterLabelController;
$error_message = $verify_data->startValidator($request->all());
if ($error_message) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 售后标签下有售后单的不得删除
$order_after = DB::table('order_after')
->whereIn('oraf_orla_id', $request['afla_id'])
->where('oraf_delete', 1)
->first();
if ($order_after) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'售后标签下有售后单不得删除']);
}
// 售后标签下有子标签不得删除
$son_afla_id = DB::table('after_label')
->whereIn('afla_parent_id', $request['afla_id'])
->where('afla_delete', 1)
->first();
if ($son_afla_id) {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'售后标签下有子标签不得删除']);
}
// 删除
$update_data['afla_delete'] = 2;//是否删除:1正常2已删除
$update_data['afla_update_time'] = date('Y-m-d H:i:s');
$cate_res = DB::table('after_label')
->whereIn('afla_id', $request['afla_id'])
->update($update_data);
if ($cate_res) {
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 查询信息
$find_afla_name = DB::table('after_label')
->whereIn('afla_id', $request['afla_id'])
->select('afla_name')
->get();
foreach ($find_afla_name as $key => $value) {
$afla_name[] = $value->afla_name;
}
Common::addLog($user_info, getRealIp($request), '售后标签', '删除', '售后标签:('.implode(',', $afla_name).')删除成功');
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>'删除成功']);
} else {
return response()->json(['code'=>500, 'msg'=>'error', 'data'=>'删除失败']);
}
}
// 获取售后标签数据
public function getAfterLabel(Request $request)
{
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
$search_data = $request->all();
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$list_data = DB::table('after_label')
->where('afla_cid', $user_info->adm_cid)
->where('afla_superior_shop_id', $shop_id)
->where('afla_state', 1)
->where('afla_delete', 1)
->where(function ($query) use ($search_data) {
if (!empty($search_data['search_data'])) {
$query->where('afla_name', 'like', '%'.$search_data['search_data'].'%');
}
})
->select('afla_id', 'afla_name')
->paginate($this->show_count);
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_data->items(); //返回数据
return response()->json(['code'=>200, 'msg'=>'success', 'data_info'=>$data_info]);
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
namespace App\Http\Controllers\Api\AfterSaleManage;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\Verify\AfterSaleManage\VerifyOrderAfterSaleController;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Api\Common;
class OrderAfterSaleController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
// 列表
public function index(Request $request)
{
// 验证数据
$verify_data = new VerifyOrderAfterSaleController;
$error_message = $verify_data->indexValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
$search_data = $request->all();
$list_data = DB::table('order_after_sale as a')
->leftJoin('order_client as b', 'b.orcl_ord_id', '=', 'a.oras_ord_id')
->leftJoin('order as c', 'c.ord_id', '=', 'a.oras_ord_id')
->where('oras_cid', $user_info->adm_cid)
->where('oras_superior_shop_id', $shop_id)
->where(function($query) use($search_data) {
if (!empty($search_data['ord_create_time'])) {
$query->where('ord_create_time', 'like', $search_data['ord_create_time'].'%' );
}
})
->where(function($query) use($search_data) {
if (!empty($search_data['ord_order_number'])) {
$query->where('ord_order_number', 'like', $search_data['ord_order_number'].'%' );
}
})
->where(function($query) use($search_data) {
if (!empty($search_data['orcl_channel_unit'])) {
$query->where('orcl_channel_unit', 'like', '%'.$search_data['orcl_channel_unit'].'%' );
}
})
->where(function($query) use($search_data) {
if (!empty($search_data['orcl_name'])) {
$query->where('orcl_name', 'like', '%'.$search_data['orcl_name'].'%' );
}
})
->where(function($query) use($search_data) {
if (!empty($search_data['orcl_phone'])) {
$query->where('orcl_phone', 'like', '%'.$search_data['orcl_phone'].'%' );
}
})
->where(function($query) use($search_data) {
if (!empty($search_data['orcl_car_num'])) {
$query->where('orcl_car_num', 'like', $search_data['orcl_car_num'].'%' );
}
})
->where(function($query) use($search_data) {
if (!empty($search_data['ord_create_id'])) {
$query->where('ord_create_id', $search_data['ord_create_id']);
}
})
->where(function($query) use($search_data) {
if (!empty($search_data['ord_state'])) {
$query->where('ord_state', $search_data['ord_state']);
}
})
->where(function($query) use($search_data) {
if (!empty($search_data['ord_type'])) {
$query->where('ord_type', $search_data['ord_type']);
}
})
->where(function($query) use($search_data) {
if (!empty($search_data['oras_state'])) {
$query->where('oras_state', $search_data['oras_state']);
}
})
->select('oras_id', 'oras_state', 'oras_reason', 'ord_id', 'ord_order_number', 'ord_goods_quantity', 'ord_actual_price', 'ord_create_id',
'ord_payment_way', 'ord_state', 'ord_wor_state', 'ord_wor_quantity', 'ord_type', 'ord_service_type',
'orcl_channel_unit', 'orcl_name', 'orcl_phone', 'orcl_car_num', 'orcl_address',
'oras_remark', 'ord_create_time', 'ord_order_price')
->orderBy('ord_id', 'desc')
->paginate($this->show_count);
$list_items = $list_data->items();
if ($list_items) {
// 查找订单商品
foreach ($list_items as $key => $value) {
$ord_id[] = $value->ord_id;
$adm_id[] = $value->ord_create_id;
}
$order_goods = DB::table('order_goods')
->whereIn('orgo_ord_id',$ord_id)
->select('orgo_ord_id','orgo_goo_id','orgo_goo_name','orgo_goo_goods_encode','orgo_goo_price',
'orgo_goo_quantity','orgo_is_recycle')
->get();
$adm_id = array_unique($adm_id);
// 查找账号id对应的账号姓名
$find_admin = DB::table('admin')
->whereIn('adm_id', $adm_id)
->select('adm_id', 'adm_name')
->get();
}else{
$order_goods = [];
$find_admin = [];
}
$data_info['current_page'] = $list_data->currentPage(); //当前页面页码
$data_info['last_page'] = $list_data->lastPage(); //表示最后一页的页码
$data_info['total'] = $list_data->total(); //总数据个数
$data_info['current_number'] = $this->show_count; //一页显示多少个
$data_info['data'] = $list_items; //返回数据
$data_info['order_goods'] = $order_goods; //订单商品数据
$data_info['find_admin'] = $find_admin; //返回数据
// 获取当前列表下的按钮
$list_button = getListButton($request['api_token'], $request['pri_id']);
if($list_data) {
return response()->json(['code'=> 200,'msg'=>'success','data'=>$data_info, 'list_button'=>$list_button]);
}else{
return response()->json(['code'=> 500,'msg'=>'error','data'=>'暂无数据']);
}
}
// 详情
public function info(Request $request)
{
// 验证数据
$verify_data = new VerifyOrderAfterSaleController;
$error_message = $verify_data->infoValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
// 查询售后订单信息
$find_order = DB::table('order as a')
->leftJoin('order_client as b', 'b.orcl_ord_id', '=', 'a.ord_id')
->leftJoin('admin as c', 'c.adm_id', '=', 'a.ord_create_id')
->where('ord_id', $request['ord_id'])
->select( 'adm_name', 'ord_order_number', 'ord_goods_quantity', 'ord_actual_price', 'ord_order_price',
'ord_payment_way', 'ord_state', 'ord_wor_state', 'ord_type', 'ord_service_type', 'ord_remark',
'orcl_channel_unit', 'orcl_name', 'orcl_phone', 'orcl_car_num', 'orcl_address')
->first();
$order_goods = DB::table('order_goods')
->where('orgo_ord_id', $request['ord_id'])
->select('orgo_goo_name', 'orgo_goo_goods_encode', 'orgo_goo_price', 'orgo_is_recycle',
'orgo_goo_quantity', 'orgo_can_assign_quantity')
->get();
$data['find_order'] = $find_order;
$data['order_goods'] = $order_goods;
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>$data]);
}
// 取消售后
public function cancel(Request $request)
{
// 验证数据
$verify_data = new VerifyOrderAfterSaleController;
$error_message = $verify_data->cancelValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$find_oras = DB::table('order_after_sale')
->where('oras_id', $request['oras_id'])
->select('oras_state', 'oras_ord_id', 'oras_order_number')
->first();
if ($find_oras->oras_state != 1) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'当前售后订单不是待处理状态无法取消售后']);
}
DB::beginTransaction();
// 1. 删除售后订单数据
$oras_res = DB::table('order_after_sale')
->where('oras_id', $request['oras_id'])
->delete();
// 2. 将订单状态改为服务中
$ord_data['ord_wor_state'] = 2;
$ord_data['ord_update_time'] = date('Y-m-d H:i:s');
$ord_res = DB::table('order')
->where('ord_id', $find_oras->oras_ord_id)
->update($ord_data);
if ($oras_res && $ord_res) {
DB::commit();
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
Common::addLog($user_info, getRealIp($request), '订单售后','取消售后','取消售后:'.$find_oras->oras_order_number.'成功');
return response()->json(["code"=>200,'msg'=>'success','data'=>'取消售后成功']);
}else{
DB::rollBack();
return response()->json(["code"=>500,'msg'=>'error','data'=>'取消售后失败']);
}
}
// 售后完成
public function finish(Request $request)
{
// 验证数据
$verify_data = new VerifyOrderAfterSaleController;
$error_message = $verify_data->cancelValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$find_oras = DB::table('order_after_sale')
->where('oras_id', $request['oras_id'])
->select('oras_state', 'oras_ord_id', 'oras_order_number')
->first();
if ($find_oras->oras_state == 1) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'当前售后订单尚未处理,无法完成']);
}
if ($find_oras->oras_state == 3) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'当前售后订单已经完成']);
}
DB::beginTransaction();
// 1. 售后订单数据
$oras_data['oras_state'] = 3;
$oras_data['oras_update_time'] = date('Y-m-d H:i:s');
$oras_res = DB::table('order_after_sale')
->where('oras_id', $request['oras_id'])
->update($oras_data);
// 2. 将订单状态改为服务中
$ord_data['ord_wor_state'] = 2;
$ord_data['ord_update_time'] = date('Y-m-d H:i:s');
$ord_res = DB::table('order')
->where('ord_id', $find_oras->oras_ord_id)
->update($ord_data);
if ($oras_res && $ord_res) {
DB::commit();
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
Common::addLog($user_info, getRealIp($request), '订单售后','售后完成','售后完成:'.$find_oras->oras_order_number.'成功');
return response()->json(["code"=>200,'msg'=>'success','data'=>'售后完成成功']);
}else{
DB::rollBack();
return response()->json(["code"=>500,'msg'=>'error','data'=>'售后完成失败']);
}
}
// 备注
public function remark(Request $request)
{
// 验证数据
$verify_data = new VerifyOrderAfterSaleController;
$error_message = $verify_data->remarkValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
$find_oras = DB::table('order_after_sale')
->where('oras_id', $request['oras_id'])
->select('oras_ord_id', 'oras_order_number')
->first();
// 1. 售后订单数据
$oras_data['oras_remark'] = $request['remark'];
$oras_data['oras_update_time'] = date('Y-m-d H:i:s');
$oras_res = DB::table('order_after_sale')
->where('oras_id', $request['oras_id'])
->update($oras_data);
if ($oras_res) {
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
Common::addLog($user_info, getRealIp($request), '订单售后','备注','售后完成:'.$find_oras->oras_order_number.'成功');
return response()->json(["code"=>200,'msg'=>'success','data'=>'备注成功']);
}else{
return response()->json(["code"=>500,'msg'=>'error','data'=>'备注失败']);
}
}
// 售后处理
public function dispose(Request $request)
{
// 【鑫世进蓄电池救援】尊敬的客户您好,已为您安排蓄电池救援技师(***,138***)点击http://*****查看进度。
// $message = "您的服务技师已出发,详情请查看:http://7cha.co/K5fdO09F";//短信信息
// $message = "尊敬的客户您好,已为您安排蓄电池救援技师(姜友灿,1381521001)点击http://7cha.co/0a9K9O5c查看进度";//短信信息
// $send_res = sendSmsCode('18514050435', $message);
// echo $send_res;die;
// 验证数据
$verify_data = new VerifyOrderAfterSaleController;
$error_message = $verify_data->disposeValidator($request->all());
if ($error_message) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数错误', 'error_message'=>$error_message]);
}
if ($request['type'] == 1) {
// 查询售后订单信息
$find_oras = DB::table('order_after_sale as a')
->leftJoin('order_client as b', 'b.orcl_ord_id', '=', 'a.oras_ord_id')
->where('oras_id', $request['oras_id'])
->select('oras_reason', 'oras_remark', 'oras_ord_id', 'orcl_channel_unit', 'orcl_name', 'orcl_phone')
->first();
$goods_data = DB::table('order_goods')
->where('orgo_ord_id', $find_oras->oras_ord_id)
->select('orgo_goo_id', 'orgo_goo_name', 'orgo_goo_goods_encode', 'orgo_goo_price',
'orgo_goo_quantity', 'orgo_can_assign_quantity')
->get();
$data['find_oras'] = $find_oras;
$data['goods_data'] = $goods_data;
return response()->json(['code'=> 200, 'msg'=>'success', 'data'=>$data]);
}
$goo_all_quantity = 0;//商品总数量
foreach ($request['goo_id'] as $key => $value) {
if (!is_numeric($value) || $value < 0 || !is_numeric($request['exchange_number'][$key]) || $request['exchange_number'][$key] < 0) {
return response()->json(['code'=> 500, 'msg'=>'error', 'data'=>'参数类型错误']);
}
$goo_all_quantity += $request['exchange_number'][$key];//商品总数量
$goo_exchange[$value] = $request['exchange_number'][$key];
}
// 获取当前操作账号信息
$user_info = Common::getUserInfo($request['api_token']);
// 判断是否为加盟店账号,shop_superior_id 为0 是总店,不为0,是总店id或加盟店id
$shop_id = $user_info->shop_superior_id ? $user_info->shop_superior_id : $user_info->adm_shop_id;
// 订单商品数量减去对应的退货数量
// 查询订单商品
$goods_data = DB::table('order_goods')
->where('orgo_ord_id', $request['ord_id'])
->whereIn('orgo_goo_id', $request['goo_id'])
->select('orgo_id', 'orgo_goo_id', 'orgo_goo_price', 'orgo_goo_quantity', 'orgo_can_assign_quantity',
'orgo_goo_name', 'orgo_goo_goods_encode')
->get();
// 更新订单商品表数量
$sql = 'UPDATE `faster_order_goods` SET ';
$goo_quantity_sql = '';
$actual_number_sql = '';
$update_time_sql = '';
$ids = '';
$goo_price = 0;//合计金额
foreach ($goods_data as $key => $value) {
// 商品订单数量
// 更改可派单商品数量
$actual_number_sql = $actual_number_sql . ' WHEN ' .$value->orgo_id;
$actual_number_sql = $actual_number_sql . ' THEN ' . ($value->orgo_can_assign_quantity - $goo_exchange[$value->orgo_goo_id]);
// 更改订单数量
$goo_quantity_sql = $goo_quantity_sql . ' WHEN ' .$value->orgo_id;
$goo_quantity_sql = $goo_quantity_sql . ' THEN ' . ($value->orgo_goo_quantity - $goo_exchange[$value->orgo_goo_id]);
// 更改时间
$update_time_sql = $update_time_sql . ' WHEN ' .$value->orgo_id;
$update_time_sql = $update_time_sql . ' THEN "' .date('Y-m-d H:i:s').'"';
$ids = $ids . $value->orgo_id.',';
$goo_price += $value->orgo_goo_price;
}
$sql = $sql .' `orgo_can_assign_quantity`= CASE `orgo_id` '.$actual_number_sql.' END,';
$sql = $sql .' `orgo_goo_quantity`= CASE `orgo_id` '.$goo_quantity_sql.' END,';
$sql = $sql .' `orgo_update_time`= CASE `orgo_id` '.$update_time_sql.' END';
$sql = $sql . ' WHERE `orgo_id` IN ('.trim($ids,',').')';
DB::beginTransaction();
$orgo_res = DB::update($sql);
// 更改订单表的订单金额、商品总数量
// 查询订单信息
$find_order = DB::table('order')
->where('ord_id', $request['ord_id'])
->select('ord_order_number', 'ord_order_price', 'ord_goods_quantity', 'ord_type', 'ord_client_id')
->first();
$ord_data['ord_order_price'] = $find_order->ord_order_price - $goo_price;
$ord_data['ord_goods_quantity'] = $find_order->ord_goods_quantity - $goo_all_quantity;
$ord_data['ord_update_time'] = date('Y-m-d H:i:s');
$ord_res = DB::table('order')->where('ord_id', $request['ord_id'])->update($ord_data);
// 售后订单状态改为售后中
$oras_data['oras_state'] = 2;
$oras_data['oras_remark'] = $request['remark'] ? $request['remark'] : '';
$oras_data['oras_update_time'] = date('Y-m-d H:i:s');
$oras_res = DB::table('order_after_sale')
->where('oras_id', $request['oras_id'])
->update($oras_data);
// 生成退货单
// 1.退换回收单表添加数据
$rec_number = 'TH' . rand(100, 999) . date('mdHis'). rand(100000, 999999); // 回收单号
$add_recycle['rec_cid'] = $user_info->adm_cid; //公司id
$add_recycle['rec_shop_id'] = $user_info->adm_shop_id; //门店id
$add_recycle['rec_superior_shop_id'] = $shop_id; //门店id
$add_recycle['rec_number'] = $rec_number; //回收单号
$add_recycle['rec_create_adm_id'] = $user_info->adm_id; //创建人id
$add_recycle['rec_date'] = date('Y-m-d'); //日期
$add_recycle['rec_price'] = $goo_price; //回收总金额(单位:分)
$add_recycle['rec_amount'] = $goo_all_quantity; //回收总数量
$add_recycle['rec_state'] = 1; //回收状态 1.未回收 2.已回收
$add_recycle['rec_type'] = $find_order->ord_type; //买家类型 1.门店零售 2.来往单位
$add_recycle['rec_ware_id'] = $request['ware_id']; //仓库id
$add_recycle['rec_remark'] = $request['remark'] ? $request['remark'] : ''; //备注
$recycle_id = DB::table('recede_recycle')->insertGetId($add_recycle);
// 2.退换回收单商品表添加数据
foreach ($goods_data as $key => $value) {
$rego_data[$key]['rego_rec_id'] = $recycle_id;
$rego_data[$key]['rego_goo_id'] = $value->orgo_id;
$rego_data[$key]['rego_goo_name'] = $value->orgo_goo_name;
$rego_data[$key]['rego_goo_goods_encode'] = $value->orgo_goo_goods_encode;
$rego_data[$key]['rego_goo_price'] = $value->orgo_goo_price;
$rego_data[$key]['rego_sell_number'] = $goo_exchange[$value->orgo_goo_id];
$rego_data[$key]['rego_recycle_number'] = $goo_exchange[$value->orgo_goo_id];
}
$add_goods = DB::table('recede_goods')->insert($rego_data);
// 3.回收单客户表添加数据
$recl_data['recl_rec_id'] = $recycle_id; //回收单id
$recl_data['recl_client_id'] = $find_order->ord_client_id; //来往单位id/客户id
$recl_data['recl_name'] = $request['client_name']; //客户姓名
$recl_data['recl_phone'] = $request['client_phone']; //联系电话
if($find_order->ord_type == 2){
$recl_data['recl_channel_unit'] = $request['orcl_channel_unit']; //渠道单位
$mem_res = true;
}else{
// 零售类型,会员对应的退货数量加1
$mem_res = DB::table('member')
->where('mem_id', $find_order->ord_client_id)
->increment('mem_retreat_trade');
}
$add_client = DB::table('recede_client')->insert($recl_data);
if ($orgo_res && $ord_res && $oras_res && $recycle_id && $add_client && $mem_res) {
DB::commit();
Common::addLog($user_info, getRealIp($request), '订单售后','售后处理',$find_order->ord_order_number.'售后处理成功');
return response()->json(["code"=>200,'msg'=>'success','data'=>'售后处理成功']);
}else{
DB::rollBack();
return response()->json(["code"=>500,'msg'=>'error','data'=>'售后处理失败']);
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
No preview for this file type
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论