Agreement.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. namespace Option\Lib;
  3. use Dever;
  4. class Agreement
  5. {
  6. private $font_size = 12;
  7. # 查看合同
  8. public function show_api()
  9. {
  10. $p = Dever::input('p');
  11. if (!$p) {
  12. Dever::alert('传入参数有误');
  13. }
  14. $p = Dever::json_decode(Dever::decode($p));
  15. if (!$p) {
  16. Dever::alert('传入参数有误');
  17. }
  18. $source = $p['source'];
  19. if ($source == 2) {
  20. # 获取当前登录的uid
  21. $aid = Dever::load('passport/user')->check(false);
  22. $aid = 18;
  23. if (!$aid || $aid <= 0) {
  24. Dever::alert('请先登录');
  25. }
  26. } else {
  27. Dever::load('manage/auth')->init();
  28. $aid = false;
  29. }
  30. $agreement_id = $p['agreement_id'];
  31. $status = $p['status'];
  32. $id = $p['id'];
  33. if ($status == 1) {
  34. $info = Dever::db('option/account')->find($id);
  35. $info['aid'] = $id;
  36. $info['create_state'] = 2;
  37. } elseif ($status == 2) {
  38. $info = Dever::db('option/agreement')->find($id);
  39. if (!$info) {
  40. Dever::alert('未生成合同');
  41. }
  42. $info['create_state'] = 1;
  43. $agreement_id = $info['agreement_id'];
  44. }
  45. $agreement = Dever::db('setting/agreement')->find($agreement_id);
  46. if (!$agreement) {
  47. Dever::alert('合同模板不存在');
  48. }
  49. if ($aid && $aid != $info['aid']) {
  50. Dever::alert('您没有权限查看');
  51. }
  52. $method = 'pdf_' . $agreement['type'];
  53. return $this->$method($agreement, $info);
  54. }
  55. # 生成跳转链接
  56. public function location_api()
  57. {
  58. Dever::load('manage/auth')->init();
  59. $id = Dever::input('id');
  60. $info = Dever::db('option/agreement')->find($id);
  61. $info = $this->name($info['agreement_id'], $info, 2, 3);
  62. Dever::location($info[1]);
  63. }
  64. # 合同名称
  65. public function name($agreement, $info, $status = -1, $source = 1)
  66. {
  67. if (is_numeric($agreement)) {
  68. $agreement = Dever::db('setting/agreement')->find($agreement);
  69. }
  70. $name = $agreement['name'];
  71. if (strstr($name, '{name}')) {
  72. $name = str_replace('{name}', $info['name'], $name);
  73. }
  74. if (strstr($name, '{date}')) {
  75. if (isset($info['sdate'])) {
  76. $sdate = date('Y年m月d日', $info['sdate']);
  77. } else {
  78. $sdate = date('Y年m月d日');
  79. }
  80. $name = str_replace('{date}', $sdate, $name);
  81. }
  82. if ($status > 0) {
  83. $param = array();
  84. $param['source'] = $source;
  85. $param['status'] = $status;
  86. $param['id'] = $info['id'];
  87. $param['agreement_id'] = $agreement['id'];
  88. $param = Dever::encode(Dever::json_encode($param));
  89. $link = Dever::url('option/lib/agreement.show?p=' . $param);
  90. if ($source == 1) {
  91. # 1 是未生成合同,预览
  92. # 2 是已生成合同
  93. $name = '<a href="'.$link.'" target="_blank">'.$name.'</a>';
  94. } else {
  95. return array($name, $link);
  96. }
  97. }
  98. return $name;
  99. }
  100. # 新建合同
  101. public function up($account, $ids, $total, $status = 1)
  102. {
  103. $agreement = Dever::db('setting/agreement')->find(array('type' => 6));
  104. if (!$agreement) {
  105. Dever::alert('协议模板不存在');
  106. }
  107. $qdate = time();
  108. $sdate = $qdate;
  109. $edate = strtotime('+3 year', $sdate);
  110. $where['aid'] = $account['id'];
  111. $where['agreement_id'] = $agreement['id'];
  112. $info = Dever::db('option/agreement')->find($where);
  113. $where['order_num'] = $this->getOrderId();
  114. $where['agreement_name'] = $this->name($agreement, $account);
  115. $where['sign'] = $account['sign'];
  116. $where['name'] = $account['name'];
  117. $where['mobile'] = $account['mobile'];
  118. $where['idcard'] = $account['idcard'];
  119. $where['idcard_front'] = $account['idcard_front'];
  120. $where['idcard_back'] = $account['idcard_back'];
  121. $where['address'] = '';
  122. $where['status'] = $status;
  123. $where['udate'] = $where['cdate'] = time();
  124. $where['qdate'] = $qdate;
  125. $where['sdate'] = $sdate;
  126. $where['edate'] = $edate;
  127. $where['jiaofu_id'] = $ids;
  128. $where['jiaofu_total'] = $total;
  129. $method = 'content_' . $agreement['type'];
  130. if ($info) {
  131. $up['content'] = Dever::array_encode($this->$method($agreement, $info));
  132. $up['where_id'] = $info['id'];
  133. $state = Dever::db('option/agreement')->update($up);
  134. } else {
  135. $up = $where;
  136. $up['content'] = Dever::array_encode($this->$method($agreement, $account));
  137. $state = Dever::db('option/agreement')->insert($up);
  138. }
  139. return $state;
  140. }
  141. # 更新合同内容
  142. public function upContent($id)
  143. {
  144. $state = false;
  145. $info = Dever::db('option/agreement')->find($id);
  146. if ($info) {
  147. $agreement = Dever::db('setting/agreement')->find($info['agreement_id']);
  148. if ($agreement) {
  149. $method = 'content_' . $agreement['type'];
  150. $up = array();
  151. $up['content'] = Dever::array_encode($this->$method($agreement, $info));
  152. $up['where_id'] = $info['id'];
  153. $state = Dever::db('option/agreement')->update($up);
  154. }
  155. }
  156. return $state;
  157. }
  158. # 作废并生成
  159. public function drop($id)
  160. {
  161. $info = Dever::db('option/agreement')->find($id);
  162. if ($info) {
  163. $agreement = Dever::db('setting/agreement')->find($info['agreement_id']);
  164. if ($agreement) {
  165. $state = Dever::db('option/agreement')->update(array('where_id' => $info['id'], 'status' => 3));
  166. if ($state) {
  167. # 生成新的合同
  168. unset($info['id']);
  169. unset($info['cdate']);
  170. unset($info['sdate']);
  171. unset($info['edate']);
  172. unset($info['qdate']);
  173. unset($info['sign']);
  174. $member = Dever::db('option/account')->find($info['aid']);
  175. $info['name'] = $member['name'];
  176. $info['idcard'] = $member['idcard'];
  177. $info['mobile'] = $member['mobile'];
  178. $info['sign'] = '';
  179. $info['status'] = 1;
  180. Dever::db('option/agreement')->insert($info);
  181. }
  182. }
  183. }
  184. }
  185. /**
  186. * 生成订单号
  187. *
  188. * @return mixed
  189. */
  190. public function getOrderId()
  191. {
  192. $where['order_num'] = Dever::order('AG');
  193. $state = Dever::db('option/agreement')->one($where);
  194. if (!$state) {
  195. return $where['order_num'];
  196. } else {
  197. return $this->getOrderId();
  198. }
  199. }
  200. public function content($name, $content)
  201. {
  202. return array('name' => $name, 'content' => $content);
  203. }
  204. public function content_6($agreement, $info)
  205. {
  206. $content = array();
  207. $content[] = $this->content('', ' 承诺人曾与中食民安(北京)科技有限公司(以下简称“中食民安”)签订《中食民安(北京)科技有限公司代理商合作协议》,为便于更好的工作,承诺人自愿成为中食民安的市场管理培训师并销售产品,为更好的开展相关工作,承诺如下:');
  208. $content[] = $this->content('一、我知悉相关定义', '市场管理培训师(以下简称培训师):是培训和辅导其管理区域内其他代理商,在进行销售渠道的拓展、营销推广技巧、公司政策的传达和讲解的辅导后,达到提升销售额、完成业绩指标,并对其他代理商进行监督和管理的身份。');
  209. $content[] = $this->content('二、我确认培训师与被培训人的关系', '1、培训师管理区域与《中食民安(北京)科技有限公司代理商合作协议》中授权区域保持一致。
  210. 2、被培训人:指每个培训师管理区域内的其他代理,被培训人以中食民安规定方式签订《中食民安(北京)科技有限公司代理商合作协议》,即视为被培训人同意成为并自愿接受培训师的培训和管理。');
  211. $content[] = $this->content('三、培训师及被培训人的权利和义务', '1、培训师的权利
  212. 1)培训师的服务费,按周结算,具体服务费标准与培训内容、培训时间另行约定;
  213. 2)管理和被管理关系存续期间,根据实际的培训情况、政策讲解的掌握、业绩完成情况,进行综合评定,评定标准见《市场管理培训费》,完成考核的培训师在每个奖励周期相应收益(包括物质和荣誉奖励,愿意服从中食民安根据实际完成情况及市场状态等定期或不定期调整奖励内容及标准)
  214. 2、培训师的义务
  215. 1)及时传达中食民安各项新颁布的通知、公告等各类文件并将内容解读清楚;
  216. 2)每周不少于三次,对被培训人进行业务培训,包括社群的建立、销售技巧、销售渠道拓展、客户服务、如何办理沙龙等;
  217. 3)随时帮助被培训人解决实际销售中遇到的任何问题。
  218. 3、被培训人的义务
  219. 1)督促并指导被培训人按照中食民安要求进行招商活动,接受中食民安监管;
  220. 2)督促并指导被培训人在培训师的培训指导下,积极开拓市场,努力完成业绩。
  221. ');
  222. $content[] = $this->content('四、其它', '1、培训师与被培训人,合作过程中出现任何争议,可申请中食民安进行协调;
  223. 2、本承诺书作为《中食民安(北京)科技有限公司代理商合作协议》的附件,是《中食民安(北京)科技有限公司代理商合作协议》的不可分割部分,我愿意遵守。
  224. ');
  225. return $content;
  226. }
  227. # 市场管理培训师承诺书
  228. public function pdf_6($agreement, $info)
  229. {
  230. $base = Dever::db('setting/base')->find();
  231. if (isset($info['qdate']) && $info['qdate']) {
  232. $qdate = date('Y年m月d日', $info['qdate']);
  233. } else {
  234. $qdate = date('Y年m月d日');
  235. }
  236. $name = $this->name($agreement, $info);
  237. $pdf = Dever::load('pdf/lib/core')->init();
  238. $pdf->SetTitle($name);
  239. $pdf->setCellHeightRatio(1.8);
  240. $pdf->setCellPaddings(10, 0, 10, 0);
  241. $pdf->font(18, 'B');
  242. $pdf->center('市场管理培训师承诺书');
  243. $pdf->br();
  244. $pdf->font($this->font_size, 'B');
  245. $pdf->left('承诺人:' . $info['name']);
  246. $pdf->left('身份证号:' . $info['idcard']);
  247. $pdf->left('电话:' . $info['mobile']);
  248. $pdf->br(2);
  249. if (isset($info['content']) && $info['content']) {
  250. $info['content'] = Dever::array_decode($info['content']);
  251. foreach($info['content'] as $k => $v) {
  252. $pdf->content($v['name'], $v['content'], $this->font_size);
  253. }
  254. } else {
  255. $method = 'content_' . $agreement['type'];
  256. $content = $this->$method($agreement, $info);
  257. foreach ($content as $k => $v) {
  258. $pdf->content($v['name'], $v['content'], $this->font_size);
  259. }
  260. if (isset($info['create_state']) && $info['create_state'] == 1) {
  261. $up = array();
  262. $up['content'] = Dever::array_encode($content);
  263. $up['where_id'] = $info['id'];
  264. $state = Dever::db('option/agreement')->update($up);
  265. }
  266. }
  267. $pdf->center(' 承诺人:');
  268. $pdf->center(' 日期:' . $qdate);
  269. $pic = Dever::pic($base['agreement_sign']);
  270. $cx = $pdf->GetX();
  271. $cy = $pdf->GetY();
  272. $x = $cx - 50;
  273. $y = $cy - 15;
  274. if ($info['sign']) {
  275. $info['sign'] = Dever::pic($info['sign']);
  276. if (strstr($info['sign'], 'http')) {
  277. $pdf->Image($info['sign'], $x, $y, 20, 20);
  278. }
  279. }
  280. $pdf->out($name);
  281. }
  282. }