Config.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 获取配置
  7. */
  8. namespace app\smartbc\controller\api\v1;
  9. use app\smartbc\controller\api\Base;
  10. use app\smartbc\model\SmartbcConfig;
  11. use app\smartbc\model\SmartbcCouponUser;
  12. use app\smartbc\model\SmartbcOrder;
  13. use app\smartbc\model\SmartbcStore;
  14. use app\smartbc\model\SmartbcStoreBill;
  15. use app\smartbc\model\SmartbcStoreGroup;
  16. use app\smartbc\model\SmartbcStoreUnion;
  17. use app\common\facade\Upload;
  18. use think\Db;
  19. class Config extends Base{
  20. /**
  21. * 获取应用配置
  22. **/
  23. public function index(){
  24. $info = SmartbcConfig::getConfig($this->miniapp->id);
  25. if(!isset($info)) {
  26. return enjson(403,'应用未配置');
  27. }
  28. $article = json_decode($info->article);
  29. $config['service_telephone'] = $info->service_telephone ??'';
  30. $config['shore_img'] = $article->shore_img ??'';
  31. $config['shore_text'] = $article->shore_text ??'';
  32. $config['mch_text'] = $article->mch_text ??'';
  33. $config['mch_qrcode'] = $article->mch_qrcode ??'';
  34. //判断用户是否商家
  35. $config['store'] = ['is_store' => 0,'info' => []];
  36. //判断是否圈主
  37. $config['group'] = [
  38. 'is_group' => 0,
  39. 'join_num' => 0,
  40. 'order' => 0,
  41. 'count' => 0,
  42. 'help' => 0,
  43. 'group_member' => $info->group_member,
  44. 'group_join' => $info->group_join,
  45. 'info' => []
  46. ];
  47. $config['user_coupon_num'] = 0; //优惠券
  48. $config['user_order_num'] = 0; //买单数
  49. $config['user_save_money'] = 0; //已省钱
  50. $config['user_bindphone'] = ""; //未绑定手机
  51. if($this->user){
  52. $config['user_bindphone'] = $this->user->phone_uid ?? ''; //未绑定手机
  53. //优惠券
  54. $config['user_coupon_num'] = SmartbcCouponUser::where(['member_miniapp_id' => $this->miniapp_id, 'is_end' => 0, 'uid' => $this->user->id])->count();
  55. //买单数
  56. $config['user_order_num'] = SmartbcOrder::where(['member_miniapp_id' => $this->miniapp_id, 'state' => 1, 'uid' => $this->user->id])->count();
  57. //已省钱
  58. $config['user_save_money'] = SmartbcCouponUser::where(['member_miniapp_id' => $this->miniapp_id, 'is_end' => 1, 'uid' => $this->user->id])->where('money', '>', 0)->sum('money');
  59. $store = SmartbcStore::manageStore($this->user->id);
  60. if ($store) {
  61. $config['store']['is_store'] = 1;
  62. $config['store']['info'] = $store->toArray();
  63. $group_ids = SmartbcStoreUnion::where(['member_miniapp_id' => $this->miniapp_id,'type' => 0,'store_id' => $store->id])->column('group_id');
  64. //圈主加群数量
  65. $config['group']['join_num'] = SmartbcStoreUnion::where(['member_miniapp_id' => $this->miniapp_id,'store_id' => $store->id,'type' => 0])->count();
  66. //买单
  67. $config['group']['order'] = SmartbcStoreBill::where(['member_miniapp_id' => $this->miniapp_id])->whereIn('store_id',SmartbcStoreUnion::where(['member_miniapp_id' => $this->miniapp_id,'type' => 0])->whereIn('group_id',$group_ids)->column('store_id'))->sum('money');
  68. //次数
  69. $config['group']['count'] = SmartbcCouponUser::where(['member_miniapp_id' => $this->miniapp_id])->whereIn('store_id',SmartbcStoreUnion::where(['member_miniapp_id' => $this->miniapp_id,'type' => 0])->whereIn('group_id',$group_ids)->column('store_id'))->count();
  70. //互助
  71. $help = 0;
  72. foreach ($group_ids as $group_id){
  73. $help += SmartbcCouponUser::where(['member_miniapp_id' => $this->miniapp_id,'is_end' => 1])->where('','EXP',Db::raw("FIND_IN_SET(".$group_id.",group_ids)"))->count();
  74. }
  75. $config['group']['help'] = $help;
  76. }
  77. $group = SmartbcStoreGroup::where(['member_miniapp_id' => $this->miniapp_id,'uid' => $this->user->id])->find();
  78. if ($group) {
  79. $config['group']['is_group'] = 1;
  80. $config['group']['info'] = $group->toArray();
  81. }
  82. }
  83. return enjson(200,'应用配置',$config);
  84. }
  85. /**
  86. * 上传图片
  87. * @return void
  88. */
  89. public function upImg(){
  90. if(request()->isPost()){
  91. $rel = Upload::index();
  92. if($rel['error'] == 0){
  93. return json(['code'=>200,'msg'=>'success','data' => $rel['url']]);
  94. }else{
  95. return json(['code'=>204,'msg'=>'error']);
  96. }
  97. }
  98. }
  99. }