where('mer_id', $mer_id)->value('agent'); if ($institution_id <= 0) return true; $institution_uid = Db::name('institution_admin')->where('mer_id', $institution_id)->value('uid'); if ($institution_uid == $order['uid']) return true; $institution_divide = Institution::where('id', $institution_id)->field('now_money,mer_special_divide,mer_store_divide,mer_event_divide,mer_data_divide,mer_test_divide')->find(); //机构分成 switch ($type) { case 0: //课程订单 $divide = bcdiv($institution_divide['mer_special_divide'], 100, 2); //百分比 if ($divide <= 0) return true; $institution_data['total_price'] = $order['total_price']; $institution_data['pay_price'] = $order['pay_price']; $institution_data['price'] = bcmul($institution_data['total_price'], $divide, 2); $institution_title = '购买课程'; $institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元'; break; case 2: //商品订单 $divide = bcdiv($institution_divide['mer_store_divide'], 100, 2); //百分比 if ($divide <= 0) return true; $institution_data['total_price'] = $order['total_price']; $institution_data['pay_price'] = $order['pay_price']; $institution_price = bcmul($institution_data['total_price'], $divide, 2); // $agent_data['price'] = bcadd($agent_price, $order['total_postage'], 2); $agent_data['price'] = $institution_price; Log::error("机构分成"); Log::error($institution_price); $institution_price = bcmul($institution_data['total_price'], $divide, 2); // $institution_data['price'] = bcadd($institution_price, $order['total_postage'], 2); $institution_data['price'] =$institution_price; $institution_title = '购买商品'; $institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元'; break; case 3: //资料订单 $divide = bcdiv($institution_divide['mer_data_divide'], 100, 2); //百分比 if ($divide <= 0) return true; $institution_data['total_price'] = $order['total_price']; $institution_data['pay_price'] = $order['pay_price']; $institution_data['price'] = bcmul($institution_data['total_price'], $divide, 2); $institution_title = '购买资料'; $institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元'; break; case 4: //报名订单 $divide = bcdiv($institution_divide['mer_event_divide'], 100, 2); //百分比 if ($divide <= 0) return true; $institution_data['total_price'] = $order['pay_price']; $institution_data['pay_price'] = $order['pay_price']; $institution_data['price'] = bcmul($institution_data['total_price'], $divide, 2); $institution_title = '活动报名'; $institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元'; break; case 5: //试卷订单 $divide = bcdiv($institution_divide['mer_test_divide'], 100, 2); //百分比 if ($divide <= 0) return true; $institution_data['total_price'] = $order['total_price']; $institution_data['pay_price'] = $order['pay_price']; $institution_data['price'] = bcmul($institution_data['total_price'], $divide, 2); $institution_title = '购买试卷'; $institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元'; break; } // 机构 $institution_data['oid'] = $order['id']; $institution_data['mer_id'] = $institution_id; $institution_data['type'] = $type; $institution_data['status'] = 1; $institution_data['add_time'] = time(); $institution_price = $institution_data['price']; if ($institution_price === "0.00") { InstitutionBill::income($institution_title, $order['id'], $institution_id, 'now_money', 'user_pay', $institution_price, bcadd($institution_divide['now_money'], $institution_price, 2), $institution_mark); Institution::commitTrans(); return true; } else { $res3 = self::set($institution_data); $res2 = Institution::setMerchantNowMoney($institution_id, $institution_price); if ($res3 && $res2) { InstitutionBill::income($institution_title, $order['id'], $institution_id, 'now_money', 'user_pay', $institution_price, bcadd($institution_divide['now_money'], $institution_price, 2), $institution_mark); Institution::commitTrans(); return true; } else { Institution::rollbackTrans(); return false; } } } /**收益统计 * @param int $mer_id * @return mixed */ public static function get_merchant_data($mer_id = 0) { $now_day = strtotime(date('Y-m-d')); //今日 $profit = InstitutionBill::where(['mer_id' => $mer_id, 'pm' => 1, 'category' => 'now_money'])->where('type', 'in', ['gold_extract', 'user_pay'])->sum('number'); $return = InstitutionBill::where(['mer_id' => $mer_id, 'pm' => 0, 'category' => 'now_money'])->where('type', 'in', ['user_refund'])->sum('number'); $data['total'] = bcsub($profit, $return, 2); $today_profit = InstitutionBill::where(['mer_id' => $mer_id, 'pm' => 1, 'category' => 'now_money'])->where('add_time', 'gt', $now_day)->where('type', 'in', ['gold_extract', 'user_pay'])->sum('number'); $today_return = InstitutionBill::where(['mer_id' => $mer_id, 'pm' => 0, 'category' => 'now_money'])->where('add_time', 'gt', $now_day)->where('type', 'in', ['user_refund'])->sum('number'); $data['today'] = bcsub($today_profit, $today_return, 2); return $data; } }