Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProductSpecValue.php 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 陈风任 <491085389@qq.com>
  11. * Date: 2019-7-9
  12. */
  13. namespace app\admin\model;
  14. use think\Model;
  15. use think\Config;
  16. use think\Db;
  17. /**
  18. * 商品规格值ID,价格,库存表
  19. */
  20. class ProductSpecValue extends Model
  21. {
  22. //初始化
  23. protected function initialize()
  24. {
  25. // 需要调用`Model`的`initialize`方法
  26. parent::initialize();
  27. $this->admin_lang = get_admin_lang();
  28. }
  29. public function ProducSpecValueEditSave($post = [], $action = 'edit')
  30. {
  31. if (!empty($post['aid']) && !empty($post['spec_price']) && !empty($post['spec_stock'])) {
  32. // 商品规格价格及规格库存
  33. $time = getTime();
  34. $saveAll = [];
  35. foreach ($post['spec_price'] as $kkk => $vvv) {
  36. $saveAll[] = [
  37. 'aid' => $post['aid'],
  38. 'spec_value_id' => $kkk,
  39. 'spec_price' => !empty($vvv['users_price']) ? $vvv['users_price'] : 0,
  40. 'spec_stock' => !empty($post['spec_stock'][$kkk]['stock_count']) ? $post['spec_stock'][$kkk]['stock_count'] : 0,
  41. 'spec_crossed_price' => !empty($post['spec_crossed_price'][$kkk]['crossed_price']) ? $post['spec_crossed_price'][$kkk]['crossed_price'] : 0,
  42. 'spec_sales_num'=> !empty($post['spec_sales'][$kkk]['spec_sales_num']) ? $post['spec_sales'][$kkk]['spec_sales_num'] : 0,
  43. 'seckill_price' => !empty($post['seckill_price'][$kkk]['spec_seckill_price']) ? $post['seckill_price'][$kkk]['spec_seckill_price'] : 0,
  44. 'seckill_stock' => !empty($post['seckill_stock'][$kkk]['spec_seckill_stock']) ? $post['seckill_stock'][$kkk]['spec_seckill_stock'] : 0,
  45. 'is_seckill' => !empty($post['seckill_stock'][$kkk]['spec_seckill_stock']) ? 1 : 0,
  46. 'discount_price' => !empty($post['discount_price'][$kkk]['spec_discount_price']) ? $post['discount_price'][$kkk]['spec_discount_price'] : 0,
  47. 'discount_stock' => !empty($post['discount_stock'][$kkk]['spec_discount_stock']) ? $post['discount_stock'][$kkk]['spec_discount_stock'] : 0,
  48. 'is_discount' => !empty($post['discount_stock'][$kkk]['spec_discount_stock']) ? 1 : 0,
  49. 'lang' => $this->admin_lang,
  50. 'add_time' => $time,
  51. 'update_time' => $time,
  52. ];
  53. }
  54. if (!empty($saveAll)) {
  55. if ('edit' === strval($action)) {
  56. // 删除当前商品下的所有规格价格库存数据
  57. $where = [
  58. 'aid' => $post['aid'],
  59. 'lang' => $this->admin_lang,
  60. ];
  61. $this->where($where)->delete(true);
  62. Db::name('product_spec_value_handle')->delete(true);
  63. }
  64. // 批量新增商品规格价格数据
  65. $this->saveAll($saveAll);
  66. }
  67. }
  68. }
  69. }