MemberauthgroupController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\MemberAuthGroup;
  5. use app\model\MemberCommission;
  6. use app\model\Coupon;
  7. use app\model\GoodsGiftcardType;
  8. use app\model\Goods;
  9. class MemberauthgroupController extends Base
  10. {
  11. function index()
  12. {
  13. $weid = weid();
  14. $keyword = input('post.keyword', '', 'serach_in');
  15. $query = MemberAuthGroup::where(['weid' => $weid]);
  16. if (!empty($keyword)) {
  17. $query->where('title', 'like', '%' . $keyword . '%');
  18. }
  19. $datalist = $query->order('sort asc,id asc')->select()->toArray();
  20. $data['data'] = $datalist;
  21. return $this->json($data);
  22. }
  23. function listUpdate()
  24. {
  25. $data = only('id,is_lookprice,is_buyright,is_default,status,sort');
  26. if (!$data['id']) throw new ValidateException('参数错误');
  27. MemberAuthGroup::update($data);
  28. return $this->json(['msg' => '操作成功']);
  29. }
  30. public function update()
  31. {
  32. $id = $this->request->post('id');
  33. $data = input('post.');
  34. if (empty($id)) {
  35. $data['weid'] = weid();
  36. try {
  37. $res = MemberAuthGroup::create($data);
  38. if ($res->id && empty($data['sort'])) {
  39. MemberAuthGroup::update(['sort' => $res->id, 'id' => $res->id]);
  40. }
  41. $this->_synupdata($data);
  42. } catch (\Exception $e) {
  43. throw new ValidateException($e->getMessage());
  44. }
  45. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  46. } else {
  47. try {
  48. MemberAuthGroup::update($data);
  49. $this->_synupdata($data);
  50. } catch (\Exception $e) {
  51. throw new ValidateException($e->getMessage());
  52. }
  53. return $this->json(['msg' => '修改成功']);
  54. }
  55. }
  56. function _synupdata($data)
  57. {
  58. MemberCommission::where('mgid', $data['id'])->delete();
  59. if (!empty($data['membercommission'])) {
  60. foreach ($data['membercommission'] as $mcvo) {
  61. if ($mcvo['return_percent'] > 0) {
  62. MemberCommission::create([
  63. 'mgid' => (int) $data['id'],
  64. 'commission_method' => $data['commission_method'],
  65. 'roletype' => $mcvo['roletype'],
  66. 'return_percent' => $mcvo['return_percent']
  67. ]);
  68. }
  69. }
  70. }
  71. }
  72. function getInfo()
  73. {
  74. $id = $this->request->post('id', '', 'serach_in');
  75. if (!$id) throw new ValidateException('参数错误');
  76. $data = MemberAuthGroup::field('*')->find($id)->toArray();
  77. if (!empty($data['upgrade_goods_id'])) {
  78. $upgrade_goods = Goods::find($data['upgrade_goods_id']);
  79. if (!empty($upgrade_goods)) {
  80. $data['upgrade_goods'] = $upgrade_goods->toArray();
  81. }
  82. }
  83. $member_commission = MemberCommission::where('mgid', $id)->select()->toArray();
  84. foreach ($member_commission as $key => $vo) {
  85. $mc[$vo['roletype']] = $vo['return_percent'];
  86. }
  87. $data['membercommission'] = getCommissionType();
  88. foreach ($data['membercommission'] as &$vo) {
  89. $vo['return_percent'] = $mc[$vo['roletype']];
  90. }
  91. return $this->json(['data' => $data]);
  92. }
  93. function delete()
  94. {
  95. return $this->del(new MemberAuthGroup());
  96. }
  97. function getField()
  98. {
  99. $data['couponarray'] = Coupon::getpcarray(2);
  100. $data['giftcardarray'] = GoodsGiftcardType::getpcarray();
  101. return $this->json(['data' => $data]);
  102. }
  103. function getCommissionType()
  104. {
  105. $data['membercommission'] = getCommissionType();
  106. return $this->json(['data' => $data]);
  107. }
  108. }