12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2021/1/26
- * Time: 15:13
- */
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class SalerStatementsDetail extends Model
- {
- public $timestamps = false;
- protected $table = 'saler_statements_detail';
- protected static $unguarded = true;
- public static function chargeSalerAmount($orderData)
- {
- $orderIds = array_column($orderData, 'order_id');
- $orderList = Order::select('final_amount','id')->whereIn('id', $orderIds)
- ->where('enable', 1)->get()->keyBy('id')->toArray();
- $statementsDetailsList = SalerStatementsDetail::selectRaw('order_id, sum(total_amount) as total_amount')
- ->whereIn('order_id', $orderIds)->groupBy('order_id')
- ->get()->keyBy('order_id')->toArray();
- foreach ($orderData as $order) {
- $orderInfo = isset($orderList[$order['order_id']]) ? $orderList[$order['order_id']] : null;
- $statementsDetailInfo = isset($statementsDetailsList[$order['order_id']]) ? $statementsDetailsList[$order['order_id']] : 0;
- if (empty($orderInfo) || ($orderInfo['final_amount'] < ($order['total_amount'] + $statementsDetailInfo['total_amount']))) {
- return false;
- }
- }
- return true;
- }
- public static function chargeSalerAmountSecond($orderData, $statemtentsId)
- {
- $orderIds = array_column($orderData, 'order_id');
- $orderList = Order::select('final_amount','id')->whereIn('id', $orderIds)
- ->where('enable', 1)->get()->keyBy('id')->toArray();
- $statementsDetailsList = SalerStatementsDetail::selectRaw('order_id, sum(total_amount) as total_amount')
- ->whereIn('order_id', $orderIds)->where('statements_id', '!=', $statemtentsId)
- ->groupBy('order_id')->get()->keyBy('order_id')->toArray();
- foreach ($orderData as $order) {
- $orderInfo = isset($orderList[$order['order_id']]) ? $orderList[$order['order_id']] : null;
- $statementsDetailInfo = isset($statementsDetailsList[$order['order_id']]) ? $statementsDetailsList[$order['order_id']] : 0;
- if (empty($orderInfo) || ($orderInfo['final_amount'] < ($order['total_amount'] + $statementsDetailInfo['total_amount']))) {
- return false;
- }
- }
- return true;
- }
- }
|