added table of co-woeker requests and new features
This commit is contained in:
@@ -18,11 +18,26 @@ class MassageController extends Controller
|
||||
{
|
||||
public function send_message(Request $request)
|
||||
{
|
||||
if($this->Config('group_sms') == 'false'){
|
||||
if (! app(ConfigService::class)->getBool('group_sms', false)) {
|
||||
throw new UnprocessableEntityHttpException('پیامک گروهی غیرفعال است.');
|
||||
}
|
||||
|
||||
$numbers = array_values(array_unique(array_filter(
|
||||
array_map('strval', (array) ($request->numbers ?? [])),
|
||||
static fn ($n) => trim($n) !== ''
|
||||
)));
|
||||
|
||||
if ($numbers === []) {
|
||||
throw new UnprocessableEntityHttpException('حداقل یک شماره لازم است.');
|
||||
}
|
||||
|
||||
// هر درخواست حداکثر ۱۰ شماره — ادمین باید دستهای بفرستد تا پنل پیامک زیر فشار نرود
|
||||
if (count($numbers) > 10) {
|
||||
throw new UnprocessableEntityHttpException('در هر درخواست حداکثر ۱۰ شماره مجاز است.');
|
||||
}
|
||||
|
||||
// یافتن مشتریان با شمارههای داده شده
|
||||
$customers = Customer::whereIn('mobile', $request->numbers)->get();
|
||||
$customers = Customer::whereIn('mobile', $numbers)->get();
|
||||
|
||||
$filter = app(SmsProfanityFilter::class);
|
||||
$filter->assertClean((string) ($request->message ?? ''));
|
||||
@@ -35,6 +50,15 @@ class MassageController extends Controller
|
||||
$this->send($customer->mobile, $message);
|
||||
}
|
||||
|
||||
// شمارههای دستی که مشتری در DB ندارند
|
||||
$known = $customers->pluck('mobile')->all();
|
||||
foreach ($numbers as $mobile) {
|
||||
if (in_array($mobile, $known, true)) {
|
||||
continue;
|
||||
}
|
||||
$this->send($mobile, (string) $request->message);
|
||||
}
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@ use App\DB\Te\TableEngine;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Services\BalanceReportService;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\WalletBalanceService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
@@ -72,4 +74,75 @@ class OrderController extends Controller
|
||||
|
||||
return response()->json($records);
|
||||
}
|
||||
|
||||
/**
|
||||
* سفارشهایی که نزد همکار (Montzar) ثبت شدهاند — فقط وقتی منبع قیمت montzar است.
|
||||
*/
|
||||
public function colleagueTable(Request $request)
|
||||
{
|
||||
$config = app(ConfigService::class);
|
||||
if (!$config->usesMontzarPricing()) {
|
||||
return response()->json([
|
||||
'message' => 'این لیست فقط وقتی منبع قیمت montzar است در دسترس است.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$hasProvider = Schema::hasColumn('orders', 'provider_id');
|
||||
$hasMontzarPrice = Schema::hasColumn('orders', 'total_price_montzar');
|
||||
|
||||
if (!$hasProvider && !$hasMontzarPrice) {
|
||||
return response()->json([
|
||||
'rows' => [],
|
||||
'total' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
$records = Order::with([
|
||||
'customer:id,name,mobile',
|
||||
'product' => static function ($q) {
|
||||
$q->withTrashed()->select(['id', 'title', 'unit']);
|
||||
},
|
||||
])->where(function ($q) use ($hasProvider, $hasMontzarPrice) {
|
||||
if ($hasProvider) {
|
||||
$q->whereNotNull('provider_id');
|
||||
}
|
||||
if ($hasMontzarPrice) {
|
||||
if ($hasProvider) {
|
||||
$q->orWhereNotNull('total_price_montzar');
|
||||
} else {
|
||||
$q->whereNotNull('total_price_montzar');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name', 'customer.mobile'])
|
||||
->select([
|
||||
'*', Order::$SELECT_STS_STR
|
||||
])->export($records);
|
||||
|
||||
if (isset($records['rows'])) {
|
||||
foreach ($records['rows'] as &$row) {
|
||||
$amount = (float) ($row['amount'] ?? 0);
|
||||
$serviceCharge = (float) ($row['service_charge'] ?? 0);
|
||||
$feeAsset = (string) ($row['fee_asset'] ?? 'rial');
|
||||
$montzarUnit = $hasMontzarPrice ? (float) ($row['total_price_montzar'] ?? 0) : 0.0;
|
||||
|
||||
// وقتی کارمزد از طلا کم شده، مقدار اولیهٔ مشتری = مقدار نزد همکار + کارمزد
|
||||
$customerAmount = $feeAsset === 'gold'
|
||||
? round($amount + $serviceCharge, 3)
|
||||
: round($amount, 3);
|
||||
|
||||
$row['customer_amount'] = $customerAmount;
|
||||
$row['colleague_amount'] = round($amount, 3);
|
||||
$row['colleague_unit_price'] = (int) round($montzarUnit);
|
||||
$row['colleague_total_price'] = (int) round($amount * $montzarUnit);
|
||||
$row['direction_label'] = Order::$DIRECTION[(int) ($row['direction'] ?? 0)]
|
||||
?? (string) ($row['direction'] ?? '');
|
||||
}
|
||||
unset($row);
|
||||
}
|
||||
|
||||
return response()->json($records);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user