123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2021/1/26
- * Time: 15:14
- */
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class Statements extends Model
- {
- protected $table = 'statements';
- public $timestamps = false;
- protected static $unguarded = true;
- public static function chargeSalerAmount($orderData, $isDiscount, $type)
- {
- //有问题,判断逻辑需排除本次提交
- return false;
- $orderIds = array_column($orderData, 'order_id');
- $orderList = Order::select('final_amount','id')->whereIn('id', $orderIds)
- ->where('enable', 1)->get()->keyBy('id')->toArray();
- $ECommerceColmus = 'actual_consumption';
- if(1 == $isDiscount) {
- $ECommerceColmus = 'discount_amount';
- }
- switch($type){
- case 3:
- $colums = $ECommerceColmus;
- break;
- default:
- $colums = 'total_amount';
- break;
- }
- $salerStatementsDetailsList = SalerStatementsDetail::selectRaw('order_id, sum(total_amount) as total_amount')
- ->whereIn('order_id', $orderIds)->where('enable', 1)->groupBy('order_id')
- ->get()->keyBy('order_id')->toArray();
- $ECommerceStatementsDetailsList = ECommerceStatementsDetail::selectRaw('order_id, sum('.$ECommerceColmus.') as total_amount')
- ->whereIn('order_id', $orderIds)->where('enable', 1)->groupBy('order_id')
- ->get()->keyBy('order_id')->toArray();
- $GameStatementsDetailsList = GameStatementsDetail::selectRaw('order_id, sum(total_amount) as total_amount')
- ->whereIn('order_id', $orderIds)->where('enable', 1)->groupBy('order_id')
- ->get()->keyBy('order_id')->toArray();
- $CPAStatementsDetailsList = CPAStatementsDetail::selectRaw('order_id, sum(total_amount) as total_amount')
- ->whereIn('order_id', $orderIds)->where('enable', 1)->groupBy('order_id')
- ->get()->keyBy('order_id')->toArray();
- foreach ($orderData as $order) {
- $orderInfo = isset($orderList[$order['order_id']]) ? $orderList[$order['order_id']] : null;
- $salerStatementsDetailInfo = isset($salerStatementsDetailsList[$order['order_id']]) ? $salerStatementsDetailsList[$order['order_id']] : 0;
- $ECommerceStatementsDetailInfo = isset($ECommerceStatementsDetailsList[$order['order_id']]) ? $ECommerceStatementsDetailsList[$order['order_id']] : 0;
- $CPAStatementsDetailInfo = isset($CPAStatementsDetailsList[$order['order_id']]) ? $CPAStatementsDetailsList[$order['order_id']] : 0;
- $GameStatementsDetailInfo = isset($GameStatementsDetailsList[$order['order_id']]) ? $GameStatementsDetailsList[$order['order_id']] : 0;
- if (empty($orderInfo) || ($orderInfo['final_amount'] < (
- $order[$colums] +
- $salerStatementsDetailInfo['total_amount'] +
- $ECommerceStatementsDetailInfo['total_amount'] +
- $CPAStatementsDetailInfo['total_amount'] +
- $GameStatementsDetailInfo['total_amount']
- ))) {
- return false;
- }
- }
- return true;
- }
- /*
- * 状态机
- */
- public static function getStatementsEnableStatus($statementsData, $user)
- {
- if ($user->role_id == 15) {
- return [2,3];
- } else if (in_array($user->role_id,[10, 17, 21])) {
- return [4,5];
- } else {
- return [];
- }
- }
- public static function chargeSalerAmountSecond($orderData, $isDiscount, $type)
- {
- $orderIds = array_column($orderData, 'order_id');
- $orderList = Order::query()
- ->select('final_amount','id')
- ->whereIn('id', $orderIds)
- ->where('enable', 1)
- ->get()
- ->keyBy('id')
- ->toArray();
- foreach ($orderData as $order) {
- $orderInfo = isset($orderList[$order['order_id']]) ? $orderList[$order['order_id']] : null;
- $orderInfo['final_amount'] = $orderInfo['final_amount'] === null ? 0 : $orderInfo['final_amount'];
- if (empty($orderInfo) || ($orderInfo['final_amount'] != $order['total_amount'] )) {
- return false;
- }
- }
- return true;
- }
- public static function chargeSalerAmountThird($orderData, $statementsId)
- {
- $orderIds = array_column($orderData, 'order_id');
- $orderList = Order::query()
- ->select('final_amount','id')
- ->whereIn('id', $orderIds)
- ->where('enable', 1)
- ->get();
- if (empty($orderList)) {
- $orderList = [];
- } else {
- $orderList = $orderList->toArray();
- $orderList = array_column($orderList, null, 'id');
- }
- if (0 != $statementsId) {
- $pddStatements = PddStatementsDetail::query()
- ->selectRaw('order_id, sum(total_amount) as total_amount')
- ->whereIn('order_id', $orderIds)
- ->where('statements_id', '!=', $statementsId)
- ->where('enable', 1)
- ->groupBy('order_id')
- ->get();
- if (empty($pddStatements)) {
- $pddStatements = [];
- } else {
- $pddStatements = $pddStatements->toArray();
- $pddStatements = array_column($pddStatements, null, 'order_id');
- }
- } else {
- $pddStatements = [];
- }
- foreach ($orderData as $order) {
- $orderInfo = isset($orderList[$order['order_id']]) ? $orderList[$order['order_id']] : null;
- $pddStatementsInfo = isset($pddStatements[$order['order_id']]) ? $pddStatements[$order['order_id']] : null;
- $orderInfo['final_amount'] = $orderInfo['final_amount'] === null ? 0 : $orderInfo['final_amount'];
- if (empty($orderInfo) || ($orderInfo['final_amount'] < ($order['total_amount'] + $pddStatementsInfo['total_amount']))) {
- return false;
- }
- }
- return true;
- }
- public static function getStatementsInfo($statementsId, $columns) {
- $statementsModel = self::query()->where('id', $statementsId);
- if(!empty($columns)) {
- $statementsModel->select($columns);
- }
- return $statementsModel->first();
- }
- public static function getListBySearch($search) {
- $statementsModel = self::query()->where('enable');
- if(isset($serach['statements_list']) && !empty($search['statements_list'])) $statementsModel->whereIn('id', $search['statements_list']);
- return $statementsModel->get();
- }
- }
|