MemberPrice.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\memberprice\model;
  11. use app\model\BaseModel;
  12. class MemberPrice extends BaseModel
  13. {
  14. /**
  15. * @param $condition
  16. * @param $data
  17. * @param $member_price
  18. * @return array
  19. */
  20. public function editGoodsMemberPrice($condition, $data, $member_price)
  21. {
  22. model('goods')->startTrans();
  23. try {
  24. model('goods')->update($data, $condition);
  25. if ($data[ 'discount_config' ] == 1) {
  26. foreach ($member_price as $k => $v) {
  27. $sku_condition = $condition;
  28. $data[ 'member_price' ] = json_encode($v);
  29. $sku_condition[] = [ 'sku_id', '=', $k ];
  30. model('goods_sku')->update($data, $sku_condition);
  31. }
  32. } else {
  33. $data[ 'member_price' ] = '';
  34. model('goods_sku')->update($data, $condition);
  35. }
  36. model('goods')->commit();
  37. return $this->success();
  38. } catch (\Exception $e) {
  39. model('goods')->rollback();
  40. return $this->error('', $e->getMessage());
  41. }
  42. }
  43. }