partylogic.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-11-18 11:26:25
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-12-29 14:44:51
  7. */
  8. namespace app\index\logic;
  9. use app\index\logic\businesslogic;
  10. use app\index\model\userinfomodel;
  11. use app\index\model\userpartymodel;
  12. use app\index\model\userpartypicturemodel;
  13. class partylogic
  14. {
  15. /**
  16. * 获取活动信息
  17. *
  18. * @param [array] $arr
  19. * @return void
  20. */
  21. public function getpartyinfo($arr)
  22. {
  23. if (!isset($arr['code']) || empty($arr['code'])) {
  24. return backarr(0, "请求失败");
  25. }
  26. $code = $arr['code'];
  27. $data = [
  28. 'type' => 'normal',
  29. 'typeid' => 1,
  30. //'code' => 'P202201121202'
  31. 'code' => $code,
  32. ];
  33. $l_bl = new businesslogic();
  34. $result = $l_bl->handlepartybusiness($data);
  35. if (1 != $result['status']) {
  36. return $result;
  37. }
  38. return backarr(1, "success", $result['data']);
  39. }
  40. /**
  41. * 用户参与活动
  42. * wj
  43. * 20220112
  44. * @return array
  45. */
  46. public function partinparty($arr)
  47. {
  48. $fillfield = ['userid', 'code'];
  49. foreach ($fillfield as $key => $value) {
  50. if (!isset($arr[$value]) || empty($arr[$value])) {
  51. return backarr(0, "请求失败");
  52. }
  53. }
  54. $userid = $arr['userid'];
  55. $code = $arr['code'];
  56. //活动业务处理
  57. $data = [
  58. 'userid' => $userid,
  59. 'type' => 'normal',
  60. 'typeid' => 1,
  61. //'code' => 'P202201121202'
  62. 'code' => $code,
  63. ];
  64. $l_bl = new businesslogic();
  65. $result = $l_bl->handlepartybusiness($data);
  66. if (1 != $result['status']) {
  67. return $result;
  68. }
  69. $partyinfo = $result['data'];
  70. $partyid = $partyinfo['id'];
  71. $m_u = new userinfomodel();
  72. $uinfo = $m_u->getInfo(['id' => $userid], ['wname', 'id', 'telno']);
  73. if (empty($uinfo)) {
  74. return backarr(0, "无用户信息");
  75. }
  76. $m_up = new userpartymodel();
  77. $where = [
  78. 'partyid' => $partyid,
  79. 'userid' => $userid,
  80. ];
  81. $upinfo = $m_up->getInfo($where);
  82. $isnew = false;
  83. if (empty($upinfo)) {
  84. $upinsertData = [
  85. 'partyid' => $partyid,
  86. 'userid' => $userid,
  87. 'createtime' => date('Y-m-d H:i:s'),
  88. ];
  89. $upid = $m_up->insertData($upinsertData);
  90. if (empty($upid)) {
  91. return backarr(0, "用户活动信息创建失败");
  92. }
  93. $where = ['id' => $upid];
  94. $upinfo = $m_up->getInfo($where);
  95. $isnew = true;
  96. }
  97. $upinfo['isnew'] = $isnew;
  98. $upinfo['userinfo'] = $uinfo;
  99. return backarr(1, "查询成功", $upinfo);
  100. }
  101. /**
  102. * 保存参与信息
  103. * wj
  104. * 20220112
  105. * @return array
  106. */
  107. public function saveinfo($arr)
  108. {
  109. if (!isset($arr['id']) || empty($arr['id'])) {
  110. return backarr(0, "请求失败");
  111. }
  112. $id = $arr['id'];
  113. $m_up = new userpartymodel();
  114. $where = [
  115. 'id' => $id,
  116. ];
  117. $upinfo = $m_up->getInfo($where);
  118. if (empty($upinfo)) {
  119. return backarr(0, '无对应信息');
  120. }
  121. $updateData = [];
  122. if (isset($arr['info']) && !empty($arr['info']) && is_string($arr['info'])) {
  123. $updateData['info'] = $arr['info'];
  124. }
  125. if (empty($updateData)) {
  126. return backarr(0, "无修改信息");
  127. }
  128. $row = $m_up->updateinfo($where, $updateData);
  129. return backarr(1, "修改成功", ['id' => $id]);
  130. }
  131. /**
  132. * 保存参与图片
  133. * wj
  134. * 20220112
  135. * @return array
  136. */
  137. public function savepicture($arr)
  138. {
  139. $m_upp = new userpartypicturemodel();
  140. $isnew = true;
  141. $id = 0;
  142. if (isset($arr['id']) && !empty($arr['id'])) {
  143. $where = [
  144. 'id' => $arr['id'],
  145. 'userid' => $arr['userid'],
  146. 'partyid' => $arr['partyid'],
  147. ];
  148. $info = $m_upp->getInfo($where);
  149. if ($info) {
  150. $isnew = false;
  151. $id = $info['id'];
  152. $updatefield = ['pictureurl'];
  153. $updateData = [];
  154. foreach ($updatefield as $key => $value) {
  155. if (isset($arr[$value]) && $arr[$value] != $info[$value]) {
  156. $updateData[$value] = $arr[$value];
  157. }
  158. }
  159. if (!empty($updateData)) {
  160. $where = ['id' => $id];
  161. $row = $m_upp->updateinfo($where, $updateData);
  162. if (empty($row)) {
  163. return backarr(0, "图片修改失败");
  164. }
  165. }
  166. }
  167. }
  168. if ($isnew) {
  169. $id = $m_upp->insertData($arr);
  170. if (empty($id)) {
  171. return backarr(0, "新增失败");
  172. }
  173. }
  174. if (empty($id)) {
  175. return backarr(0, "操作失败");
  176. }
  177. return backarr(1, "新增成功", ['id' => $id]);
  178. }
  179. /**
  180. * 获取上传图片
  181. * wj
  182. * 20220112
  183. * @return array
  184. */
  185. public function getpicture($arr)
  186. {
  187. $m_upp = new userpartypicturemodel();
  188. $where = [
  189. 'partyid' => $arr['partyid'],
  190. 'userid' => $arr['userid'],
  191. ];
  192. $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
  193. $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
  194. $count = $m_upp->getList($where, "count");
  195. if ($count <= 0) {
  196. return backarr(0, "无数据");
  197. }
  198. $list = $m_upp->getList($where, "*", $page, $size, 'sort asc');
  199. $data = [
  200. 'count' => $count,
  201. 'list' => $list,
  202. ];
  203. return backarr(1, "新增成功", $data);
  204. }
  205. /**
  206. * 设置上传完成
  207. * wj
  208. * 20220114
  209. * @return array
  210. */
  211. public function setisoverbyid($arr)
  212. {
  213. if (!isset($arr['id']) || empty($arr['id'])) {
  214. return backarr(0, "请求失败");
  215. }
  216. $id = $arr['id'];
  217. $m_up = new userpartymodel();
  218. $where = [
  219. 'id' => $id,
  220. ];
  221. $upinfo = $m_up->getInfo($where);
  222. if (empty($upinfo)) {
  223. return backarr(0, '无对应信息');
  224. }
  225. $updateData = ['isover' => 1];
  226. $row = $m_up->updateinfo($where, $updateData);
  227. return backarr(1, "修改成功", ['id' => $id]);
  228. }
  229. }