xhOrderDayNumService.php 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace common\services;
  3. use Yii;
  4. use common\models\xhOrderDayNum;
  5. use common\components\dict;
  6. class xhOrderDayNumService {
  7. /**
  8. * 增加一条订单数
  9. */
  10. public static function addOne($time,$sjId)
  11. {
  12. $order = self::getByIds($time, $sjId);
  13. if(empty($order)){
  14. $data = ['time'=>$time,'riseNum'=>1,'totalNum'=>1,'sjId'=>$sjId];
  15. self::add($data);
  16. }else{
  17. $newRiseNum = $order['riseNum'] + 1;
  18. $newTotalNum = $order['totalNum'] + 1;
  19. $data = ['riseNum'=>$newRiseNum,'totalNum'=>$newTotalNum];
  20. self::updateByIds($time, $sjId, $data);
  21. }
  22. return $data;
  23. }
  24. public static function updateByIds($time,$sjId,$data)
  25. {
  26. xhOrderDayNum::updateByCondition(['time'=>$time,'sjId'=>$sjId], $data);
  27. }
  28. public static function add($data)
  29. {
  30. $return = xhOrderDayNum::add($data);
  31. return $return;
  32. }
  33. public static function getByIds($time,$sjId)
  34. {
  35. $order = xhOrderDayNum::find()->where(['time'=>$time,'sjId'=>$sjId])->asArray()->one();
  36. return $order;
  37. }
  38. }