mardi 23 novembre 2021

Laravel - calculate total amount according to json array

I have Below Types Of Dynamic Json array, Now I want to create an amount based on channel like,

if I have channel 300 then it's 300*1 = 300

if channel 600 then its amount = (399 *1) + ((600-399) * 2)

if channel 1000 then amount should be = (399 *1) + ((700-399) * 2) + ((1000-700) * 3)

First, find a channel between which array row and then multiply by amount field.

[
  {
    "id": 1,
    "name": "tier1",
    "from": 1,
    "to": 399,
    "amount": 1,
    "channel_type": 1,
    "status": 1
  },
  {
    "id": 2,
    "name": "tier2",
    "from": 400,
    "to": 700,
    "amount": 2,
    "channel_type": 1,
    "status": 1
  },
  {
    "id": 3,
    "name": "tier3",
    "from": 701,
    "to": 1000,
    "amount": 3,
    "channel_type": 1,
    "status": 1
  }
]

Please suggest me smallest solution to this question, because I am processing by hard code, provide me with an easy and clean solution.

Thank you in advance and sorry for my poor English.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3DMZ3Th
via IFTTT

Aucun commentaire:

Enregistrer un commentaire