123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2021/4/7
- * Time: 14:26
- */
- namespace App\Http\Controllers\Api;
- use App\Models\OrderMcn;
- use App\Models\CPAStatementsDetail;
- use App\Models\StatementsSeal;
- use App\Services\ToolService;
- use Illuminate\Http\Request;
- use App\Models\Order;
- use App\Models\OrderEditRecords;
- use App\Models\OrderIncome;
- use App\Models\Statements;
- use App\Models\GameStatementsDetail;
- use App\Models\OrderCost;
- use App\Models\PddStatementsDetail;
- use App\Models\McnStatementsDetail;
- use App\Models\CustomerInvoices;
- use App\Models\CustomerInvoiceOrders;
- class ToolController extends Controller
- {
- public function updateOrderData()
- {
- $taskIdList = [
- '6986088715269439495',
- '6982825563635318791',
- '6985387528924692487',
- '6983129980322447374',
- '6982823120826531876'
- ];
- $month = '2021-07-01';
- foreach($taskIdList as $taskId) {
- # 查询订单基础信息,为了将订单原始信息保存到修改记录表中
- $info = Order::where('month', $month)->where('enable', 1)
- ->where('task_id', $taskId)->first();
- # 订单id
- $id = $info->id;
- # 订单信息格式化
- $old = json_decode(json_encode($info), 1);
- # 填写邮件中申请的理由
- $op_reason = '邮件申请修改,申请理由:现由于消耗表后台7月星图抖音消耗有五单任务对应媒体名称有误,商务端已开票,无法直接修改后台,导致成本发票对应不上,故申请修改消耗表后台部分任务的媒体名称及对应成本公司。';
- # 填写要修改的字段以及值
- $after = ['cost_company_name' => '武汉巨量星图科技有限公司', 'media_name' => '星图1-短视频'];
- # 保存修改记录,默认自动审核通过
- #OrderEditRecords::addRecord($id, $old, $after, $op_reason);
- #Order::where('id', $id)->update($after);
- # 按照修改的字段分别更新不同表数据
- #OrderIncome::where('order_id', $id)->update($after);
- #OrderCost::where('order_id', $id)->update($after);
- #OrderMcn::where('order_id', $id)->update($after);
- }
- return self::returnValue(['修改完成']);
- }
- public function deleteStatements(Request $request)
- {
- $statementsId = $request->input('id');
- \DB::beginTransaction();
- try{
- # 查询结算单基础信息
- $statementsInfo = Statements::query()
- ->where('id', $statementsId)
- ->where('enable', 1)
- ->first();
- if(empty($statementsInfo)) {
- return self::returnValue(['error' => '结算单已删除,无需重复操作'], 1102);
- }
- # 查询结算单盖章信息
- $search['statements_id'] = $statementsId;
- $statementsSealInfo = StatementsSeal::getStatementsSealInfoBySearch($search, ['id', 'verify_status', 'seal_status', 'file_status']);
- if(!empty($statementsSealInfo)) {
- if(1 == $statementsSealInfo->seal_status || 1 == $statementsSealInfo->file_status) {
- return self::returnValue(['error' => '结算单已标记盖章或归档,请取消标记后操作'], 1102);
- }
- StatementsSeal::updateData([$statementsSealInfo->id], ['enable' => 0]);
- }
- # 用来判断是否需要更新发票状态字段
- $invoiceFlag = false;
- # 查询结算单对应的发票信息
- $customerInvoicesInfo = CustomerInvoices::query()
- ->where('statements_id', $statementsId)
- ->where('enable', 1)
- ->first();
- if(!empty($customerInvoicesInfo)) {
- $invoiceFlag = true;
- if($customerInvoicesInfo->is_invoiced == 1) {
- return self::returnValue(['error' => '已经标记开票,请取消标记后走系统发票作废流程'], 1102);
- }
- if($customerInvoicesInfo->status == 4) {
- return self::returnValue(['error' =>'发票已审核通过,请走系统发票作废流程'], 1102);
- }
- # 处理发票相关信息
- $invId = $customerInvoicesInfo->id;
- CustomerInvoices::query()
- ->where('id', $invId)
- ->update(['enable' => 0, 'is_show' => 0]);
- CustomerInvoiceOrders::query()
- ->where('inv_id', $invId)
- ->update(['enable' => 0, 'is_show' => 0]);
- }
- $statementsType = $statementsInfo->type;
- $isMcn = false;
- switch($statementsType) {
- # 拼多多
- case 6:
- $orderIdList = PddStatementsDetail::query()
- ->where('statements_id', $statementsId)
- ->get()
- ->toArray();
- PddStatementsDetail::query()
- ->where('statements_id', $statementsId)
- ->where('enable', 1)
- ->update(['enable' => 0]);
- break;
- case 5:
- $orderIdList = GameStatementsDetail::query()
- ->where('statements_id', $statementsId)
- ->get()
- ->toArray();
- GameStatementsDetail::query()
- ->where('statements_id', $statementsId)
- ->where('enable', 1)
- ->update(['enable' => 0]);
- break;
- case 4:
- $orderIdList = CPAStatementsDetail::query()
- ->where('statements_id', $statementsId)
- ->get()
- ->toArray();
- CPAStatementsDetail::query()
- ->where('statements_id', $statementsId)
- ->where('enable', 1)
- ->update(['enable' => 0]);
- break;
- case 2:
- $orderIdList = McnStatementsDetail::query()
- ->where('statements_id', $statementsId)
- ->get()
- ->toArray();
- $isMcn = true;
- McnStatementsDetail::query()
- ->where('statements_id', $statementsId)
- ->where('enable', 1)
- ->update(['enable' => 0]);
- break;
- default:
- return self::returnValue(['error' => '结算单类型不存在'], 1102);
- break;
- }
- $orderIdList = array_column($orderIdList, 'order_id');
- Statements::query()
- ->where('id', $statementsId)
- ->update(['enable' => 0]);
- $updateStatus = ['statements_status' => 0];
- if($invoiceFlag) {
- $updateStatus['invoice_status'] = 0;
- }
- if($isMcn) {
- OrderMcn::query()
- ->whereIn('order_id', $orderIdList)
- ->update($updateStatus);
- } else {
- OrderIncome::query()
- ->whereIn('order_id', $orderIdList)
- ->update($updateStatus);
- }
- \DB::commit();
- return self::returnValue(true, 0);
- } catch (\Exception $exception) {
- \DB::rollBack();
- return self::returnValue(false, 500, $exception->getFile() . '(' . $exception->getLine() . '):' . $exception->getMessage());
- }
- }
- public static function getEditRecords(Request $request)
- {
- $monthStr = $request->input('month_str');
- $monthList = explode(',', $monthStr);
- $editRecordList = OrderEditRecords::query()
- ->where('status', '>', 0)
- ->whereIn('month', $monthList)
- ->where('is_show', 1)
- ->get()
- ->toArray();
- $result = [];
- return self::returnValue($result);
- foreach($editRecordList as $value) {
- if(0 == $value['is_batch']) {
- $afterData = json_decode($value['after_data'], 1);
- foreach($afterData as $key=>$data) {
- $result[$key] = isset($result[$key]) ? $result[$key] + 1 : 1;
- }
- } else {
- $result['final_amount'] = isset($result['final_amount']) ? $result['final_amount'] + 1 : 1;
- }
- }
- return self::returnValue($result);
- }
- public static function preAuditRecordSave(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'type' => 'required|in:1,2,3,4,5,6',
- 'data_id_list' => 'required|array',
- 'status' => 'required|int',
- 'content' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $type = $request->input('type');
- $dataIdList = $request->input('data_id_list');
- $status = $request->input('status');
- $content = $request->input('content');
- $errcode = 0;
- ToolService::preAuditRecordSave($type, $dataIdList, $status, $content, $errcode);
- return self::returnValue('', $errcode);
- }
- public static function getPreAuditRecord(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'type' => 'required|in:1,2,3,4,5,6',
- 'data_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $type = $request->input('type');
- $dataId = $request->input('data_id');
- $data = ToolService::getPreAuditRecord($type, [$dataId]);
- $res = isset($data[0]) ? $data[0] : [];
- return self::returnValue($res);
- }
- # 根据回款日期获取订单月份
- public static function getMonthListByPaymentDate(Request $request) {
- }
- }
|