public static function getStatisticsByCustomerID($customerID)
 {
     $details = CustomerCommodityStatistics::where('customer_id', $customerID)->get();
     if ($details) {
         $details = $details->toArray();
     } else {
         $details = [];
     }
     foreach ($details as &$detail) {
         $detail['commodity'] = Commodity::withTrashed()->find($detail['commodity_id'])->toArray();
     }
     return $details;
 }
Beispiel #2
0
 public function updateCommodityStatistics($userId, $commodityId)
 {
     $statistics = CustomerCommodityStatistics::where('customer_id', $userId)->where('commodity_id', $commodityId)->first();
     if (!$statistics) {
         $statistics = new CustomerCommodityStatistics();
         $statistics->customer_id = $userId;
         $statistics->commodity_id = $commodityId;
         $statistics->count = 0;
     }
     /*if>*/
     $statistics->count += 1;
     $statistics->save();
 }