Sellerspec.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /*
  3. * 店铺规格值
  4. * 每个店铺都有对应分类下保存的规格值
  5. */
  6. namespace app\api\controller;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Sellerspec extends MobileSeller {
  21. public function initialize() {
  22. parent::initialize();
  23. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerspec.lang.php');
  24. }
  25. /**
  26. * @api {POST} api/Sellerspec/save_spec 保存规格值
  27. * @apiVersion 1.0.0
  28. * @apiGroup Sellerspec
  29. *
  30. * @apiHeader {String} X-DS-KEY 卖家授权token
  31. *
  32. * @apiParam {Int} gc_id 商品分类ID
  33. * @apiParam {Object} spec_list 规格列表
  34. *
  35. * @apiSuccess {String} code 返回码,10000为成功
  36. * @apiSuccess {String} message 返回消息
  37. * @apiSuccess {Object} result 返回数据
  38. */
  39. public function save_spec() {
  40. $spec_list = input('post.spec_list/a');
  41. $gc_id = intval(input('post.gc_id'));
  42. if (empty($spec_list) || $gc_id <= 0) {
  43. ds_json_encode(10001, lang('param_error'));
  44. }
  45. $spec_model = model('spec');
  46. foreach ($spec_list as $sp_id => $spec) {
  47. $spvalue_ids = array();
  48. $specvalue_list = array();
  49. foreach ($spec['value'] as $val) {
  50. $val['spvalue_name'] = trim($val['spvalue_name']);
  51. if (!empty($val['spvalue_name'])) {
  52. if (isset($val['spvalue_id'])) {
  53. $spvalue_ids[] = $val['spvalue_id'];
  54. $condition = array();
  55. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  56. $condition[] = array('spvalue_id', '=', $val['spvalue_id']);
  57. $update = array(
  58. 'spvalue_name' => $val['spvalue_name'],
  59. );
  60. $spec_model->editSpecvalue($update, $condition);
  61. } else {
  62. $specvalue_list[] = array(
  63. 'spvalue_name' => $val['spvalue_name'],
  64. 'sp_id' => $sp_id,
  65. 'gc_id' => $gc_id,
  66. 'store_id' => $this->store_info['store_id'],
  67. 'spvalue_color' => '',
  68. 'spvalue_sort' => 255
  69. );
  70. }
  71. }
  72. }
  73. $condition = array();
  74. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  75. $condition[] = array('sp_id', '=', $sp_id);
  76. if (!empty($spvalue_ids)) {
  77. $condition[] = array('spvalue_id', 'not in', $spvalue_ids);
  78. }
  79. $spec_model->delSpecvalue($condition);
  80. if (!empty($specvalue_list)) {
  81. $spec_model->addSpecvalueALL($specvalue_list);
  82. }
  83. }
  84. ds_json_encode(10000, lang('ds_common_op_succ'));
  85. }
  86. }
  87. ?>