xhOrderMonthNumService.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace common\services;
  3. use Yii;
  4. use common\models\xhOrderMonthNum;
  5. use common\components\dict;
  6. class xhOrderMonthNumService {
  7. /**
  8. * 增加一条订单数
  9. */
  10. public static function addOne($year,$month,$sjId)
  11. {
  12. $order = self::getByIds($year,$month,$sjId);
  13. if(empty($order)){
  14. $data = ['year'=>date("Y"),'month'=>date("m"),'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($year,$month,$sjId, $data);
  21. }
  22. return $data;
  23. }
  24. public static function updateByIds($year,$month,$sjId,$data)
  25. {
  26. xhOrderMonthNum::updateByCondition(['year'=>$year,'month'=>$month,'sjId'=>$sjId], $data);
  27. }
  28. public static function add($data)
  29. {
  30. $return = xhOrderMonthNum::add($data);
  31. return $return;
  32. }
  33. public static function getByIds($year,$month,$sjId)
  34. {
  35. $order = xhOrderMonthNum::find()->where(['year'=>$year,'month'=>$month,'sjId'=>$sjId])->asArray()->one();
  36. return $order;
  37. }
  38. }